Fix usermod crash

Return newly allocated pointers when the caller will free them.

Closes #110
This commit is contained in:
fariouche 2018-05-08 21:17:46 -05:00 committed by Serge Hallyn
parent f50603a5fc
commit 73a876a056
2 changed files with 7 additions and 5 deletions

View File

@ -333,7 +333,7 @@ extern struct group *prefix_getgr_nam_gid(const char *grname)
&& (gid == (gid_t)gid)) {
return prefix_getgrgid ((gid_t) gid);
}
return prefix_getgrnam (grname);
return __gr_dup(prefix_getgrnam (grname));
}
else
return getgr_nam_gid(grname);

View File

@ -1251,11 +1251,13 @@ static void process_flags (int argc, char **argv)
prefix_user_home = xmalloc(len);
wlen = snprintf(prefix_user_home, len, "%s/%s", prefix, user_home);
assert (wlen == (int) len -1);
if (user_newhome) {
len = strlen(prefix) + strlen(user_newhome) + 2;
prefix_user_newhome = xmalloc(len);
wlen = snprintf(prefix_user_newhome, len, "%s/%s", prefix, user_newhome);
assert (wlen == (int) len -1);
}
len = strlen(prefix) + strlen(user_newhome) + 2;
prefix_user_newhome = xmalloc(len);
wlen = snprintf(prefix_user_newhome, len, "%s/%s", prefix, user_newhome);
assert (wlen == (int) len -1);
}
else {
prefix_user_home = user_home;