]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
ensure struct passwd fields are non-NULL in pwcopy
authorzhangjun <zhangjun-tc@dfmc.com.cn>
Fri, 22 Aug 2025 08:49:07 +0000 (16:49 +0800)
committerDamien Miller <djm@mindrot.org>
Mon, 29 Sep 2025 23:48:35 +0000 (09:48 +1000)
Android libc can return NULL pw_gecos, for example.

misc.c

diff --git a/misc.c b/misc.c
index 239ed12384cd437ea8666379e4df0d81e5ebd275..ce77ec94306755db85700602fb9fac9f63795199 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -506,7 +506,7 @@ pwcopy(struct passwd *pw)
        copy->pw_name = xstrdup(pw->pw_name);
        copy->pw_passwd = xstrdup(pw->pw_passwd == NULL ? "*" : pw->pw_passwd);
 #ifdef HAVE_STRUCT_PASSWD_PW_GECOS
-       copy->pw_gecos = xstrdup(pw->pw_gecos);
+       copy->pw_gecos = xstrdup(pw->pw_gecos == NULL ? "" : pw->pw_gecos);
 #endif
        copy->pw_uid = pw->pw_uid;
        copy->pw_gid = pw->pw_gid;
@@ -517,10 +517,10 @@ pwcopy(struct passwd *pw)
        copy->pw_change = pw->pw_change;
 #endif
 #ifdef HAVE_STRUCT_PASSWD_PW_CLASS
-       copy->pw_class = xstrdup(pw->pw_class);
+       copy->pw_class = xstrdup(pw->pw_class == NULL ? "" : pw->pw_class);
 #endif
-       copy->pw_dir = xstrdup(pw->pw_dir);
-       copy->pw_shell = xstrdup(pw->pw_shell);
+       copy->pw_dir = xstrdup(pw->pw_dir == NULL ? "" : pw->pw_dir);
+       copy->pw_shell = xstrdup(pw->pw_shell == NULL ? "" : pw->pw_shell);
        return copy;
 }