summaryrefslogtreecommitdiffstats
path: root/lib/libutil
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>1996-06-06 12:10:01 +0000
committerderaadt <deraadt@openbsd.org>1996-06-06 12:10:01 +0000
commit1bfae893c4e1654744b56dba824a14ee45be9543 (patch)
treebf3ad7767dfcdff4e1c039a8b97648e46158e878 /lib/libutil
parentuse system, so that $EDITOR expansion works (diff)
downloadwireguard-openbsd-1bfae893c4e1654744b56dba824a14ee45be9543.tar.xz
wireguard-openbsd-1bfae893c4e1654744b56dba824a14ee45be9543.zip
system() $EDITOR safely
Diffstat (limited to 'lib/libutil')
-rw-r--r--lib/libutil/passwd.c12
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)