From f1bbc8cde6bd02cdf1742f706b0f4915fc5cec65 Mon Sep 17 00:00:00 2001 From: das Date: Mon, 17 Mar 2003 02:12:55 +0000 Subject: Make pw_edit() use /bin/sh to interpret the EDITOR environment variable. PR: 48748 Reviewed by: mike (mentor) --- lib/libutil/pw_util.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/libutil/pw_util.c b/lib/libutil/pw_util.c index d219917..5eb0953 100644 --- a/lib/libutil/pw_util.c +++ b/lib/libutil/pw_util.c @@ -62,7 +62,6 @@ static const char rcsid[] = #include #include #include -#include #include #include #include @@ -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 */ -- cgit v1.1