Skip to content

Conversation

@liungkejin
Copy link

No description provided.

@wolfpld
Copy link
Owner

wolfpld commented Jan 15, 2026

And what does this do?

@liungkejin
Copy link
Author

const auto passwd = getpwuid( getuid() );
   if( passwd && *passwd->pw_gecos ) return passwd->pw_gecos;

if passwd is not nullptr, but passwd->pw_gecos is nullptr, this code will crash. I encountered this crash while running my Android executable program—not an Android app, but an executable that runs in the Android shell environment.

@wolfpld
Copy link
Owner

wolfpld commented Jan 16, 2026

Great, the Android implementation is against what the man page shows as valid code.

           s = getpwnam_r(argv[1], &pwd, buf, bufsize, &result);
           if (result == NULL) {
               if (s == 0)
                   printf("Not found\n");
               else {
                   errno = s;
                   perror("getpwnam_r");
               }
               exit(EXIT_FAILURE);
           }

           printf("Name: %s; UID: %jd\n", pwd.pw_gecos,
                  (intmax_t) pwd.pw_uid);

It's also cute how the gecos field is not set anywhere.

    /*
     * pw_passwd is non-POSIX and unused (always NULL) in bionic.
     * pw_gecos is non-POSIX and missing in bionic.
     */
    dst->pw_passwd = NULL;

Anyways. The dereference is intentional and should not be removed.

@liungkejin
Copy link
Author

Or perhaps it should be changed to

if( passwd && passwd->pw_gecos && *passwd->pw_gecos )

@wolfpld
Copy link
Owner

wolfpld commented Jan 17, 2026

Yes, that's what I hinted at.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants