Skip to content

Commit d343df4

Browse files
zhangjundjmdjm
authored andcommitted
ensure struct passwd fields are non-NULL in pwcopy
Android libc can return NULL pw_gecos, for example.
1 parent 893a579 commit d343df4

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

misc.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ pwcopy(struct passwd *pw)
506506
copy->pw_name = xstrdup(pw->pw_name);
507507
copy->pw_passwd = xstrdup(pw->pw_passwd == NULL ? "*" : pw->pw_passwd);
508508
#ifdef HAVE_STRUCT_PASSWD_PW_GECOS
509-
copy->pw_gecos = xstrdup(pw->pw_gecos);
509+
copy->pw_gecos = xstrdup(pw->pw_gecos == NULL ? "" : pw->pw_gecos);
510510
#endif
511511
copy->pw_uid = pw->pw_uid;
512512
copy->pw_gid = pw->pw_gid;
@@ -517,10 +517,10 @@ pwcopy(struct passwd *pw)
517517
copy->pw_change = pw->pw_change;
518518
#endif
519519
#ifdef HAVE_STRUCT_PASSWD_PW_CLASS
520-
copy->pw_class = xstrdup(pw->pw_class);
520+
copy->pw_class = xstrdup(pw->pw_class == NULL ? "" : pw->pw_class);
521521
#endif
522-
copy->pw_dir = xstrdup(pw->pw_dir);
523-
copy->pw_shell = xstrdup(pw->pw_shell);
522+
copy->pw_dir = xstrdup(pw->pw_dir == NULL ? "" : pw->pw_dir);
523+
copy->pw_shell = xstrdup(pw->pw_shell == NULL ? "" : pw->pw_shell);
524524
return copy;
525525
}
526526

0 commit comments

Comments
 (0)