diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-06-06 12:10:05 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 1996-06-06 12:10:05 +0000 |
commit | 95ce34efe94dfde536b356b88b5f27f3b7e7f383 (patch) | |
tree | 8d0139ffd8d999fe7ab580cf24fe91153aec6dab /lib/libutil/passwd.c | |
parent | ee305bb7990cf6945309f59e90e3a4ad3b30cbce (diff) |
system() $EDITOR safely
Diffstat (limited to 'lib/libutil/passwd.c')
-rw-r--r-- | lib/libutil/passwd.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/lib/libutil/passwd.c b/lib/libutil/passwd.c index c473eca72dc..0d03133d3e3 100644 --- a/lib/libutil/passwd.c +++ b/lib/libutil/passwd.c @@ -154,19 +154,21 @@ pw_edit(notsetuid, filename) filename = _PATH_MASTERPASSWD_LOCK; if (!(editor = getenv("EDITOR"))) editor = _PATH_VI; - if (p = strrchr(editor, '/')) - ++p; - else - p = editor; + + p = malloc(strlen(editor) + 1 + strlen(filename) + 1); + if (p == NULL) + return; + sprintf(p, "%s %s", editor, filename); if (!(editpid = vfork())) { if (notsetuid) { setgid(getgid()); setuid(getuid()); } - execlp(editor, p, filename, NULL); + system(p); _exit(1); } + free(p); for (;;) { editpid = waitpid(editpid, (int *)&pstat, WUNTRACED); if (editpid == -1) |