vipw: don't modify environment, check strtok() return value

Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2012-02-01 12:41:25 +01:00
parent 701e2b8e53
commit 467d50fa92
1 changed files with 6 additions and 4 deletions

View File

@ -215,11 +215,13 @@ static void pw_edit(int notsetuid)
{
int pstat;
pid_t pid;
char *p, *editor;
char *p, *editor, *tk;
if (!(editor = getenv("EDITOR")))
editor = strdup(_PATH_VI); /* adia@egnatia.ee.auth.gr */
if ((p = strrchr(strtok(editor, " \t"), '/')) != NULL)
editor = getenv("EDITOR");
editor = strdup(editor ? editor : _PATH_VI);
tk = strtok(editor, " \t");
if (tk && (p = strrchr(tk, '/')) != NULL)
++p;
else
p = editor;