diff options
author | David Schultz <das@FreeBSD.org> | 2003-03-17 02:12:55 +0000 |
---|---|---|
committer | David Schultz <das@FreeBSD.org> | 2003-03-17 02:12:55 +0000 |
commit | 5d907c3dd26e682d97d2c8e570dc8a5f11641e49 (patch) | |
tree | e254e1b0ff2c9c980f507fcda0bbbfffad1441c0 /lib | |
parent | f35f81b703b31f82f39de4c95f2289a627ffb0e3 (diff) | |
download | src-5d907c3dd26e682d97d2c8e570dc8a5f11641e49.tar.gz src-5d907c3dd26e682d97d2c8e570dc8a5f11641e49.zip |
Make pw_edit() use /bin/sh to interpret the EDITOR environment
variable.
PR: 48748
Reviewed by: mike (mentor)
Notes
Notes:
svn path=/head/; revision=112328
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libutil/pw_util.c | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/lib/libutil/pw_util.c b/lib/libutil/pw_util.c index d2199176c15d..5eb09535c709 100644 --- a/lib/libutil/pw_util.c +++ b/lib/libutil/pw_util.c @@ -62,7 +62,6 @@ static const char rcsid[] = #include <ctype.h> #include <fcntl.h> #include <inttypes.h> -#include <libgen.h> #include <paths.h> #include <pwd.h> #include <signal.h> @@ -290,6 +289,8 @@ pw_edit(int notsetuid) { struct stat st1, st2; const char *editor; + char *editcmd; + int editcmdlen; int pstat; if ((editor = getenv("EDITOR")) == NULL) @@ -305,8 +306,17 @@ pw_edit(int notsetuid) (void)setgid(getgid()); (void)setuid(getuid()); } + if ((editcmdlen = sysconf(_SC_ARG_MAX) - 6) <= 0 || + (editcmd = malloc(editcmdlen)) == NULL) + _exit(EXIT_FAILURE); + if (snprintf(editcmd, editcmdlen, "%s %s", + editor, tempname) >= editcmdlen) { + free(editcmd); /* pedantry */ + _exit(EXIT_FAILURE); + } errno = 0; - execlp(editor, basename(editor), tempname, NULL); + execl(_PATH_BSHELL, "sh", "-c", editcmd, NULL); + free(editcmd); _exit(errno); default: /* parent */ |