summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authordas <das@FreeBSD.org>2003-03-17 02:12:55 +0000
committerdas <das@FreeBSD.org>2003-03-17 02:12:55 +0000
commitf1bbc8cde6bd02cdf1742f706b0f4915fc5cec65 (patch)
treee254e1b0ff2c9c980f507fcda0bbbfffad1441c0 /lib
parent86c427b4c189042ac44153bde3ac62f976e418c4 (diff)
downloadFreeBSD-src-f1bbc8cde6bd02cdf1742f706b0f4915fc5cec65.zip
FreeBSD-src-f1bbc8cde6bd02cdf1742f706b0f4915fc5cec65.tar.gz
Make pw_edit() use /bin/sh to interpret the EDITOR environment
variable. PR: 48748 Reviewed by: mike (mentor)
Diffstat (limited to 'lib')
-rw-r--r--lib/libutil/pw_util.c14
1 files 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 <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 */
OpenPOWER on IntegriCloud