deffname: do not segfault when getpwuid() has no entry for the current uid On a minimal target the user running birthday may have no entry in /etc/passwd, so getpwuid(getuid()) returns NULL and the old code dereferenced it (strcpy(buf, NULL->pw_dir)) => segmentation fault. Fall back to $HOME when there is no passwd entry, and exit with a clear error message when neither is available. --- a/bdengine.c +++ b/bdengine.c @@ -309,9 +309,20 @@ { #if defined(UNIX) char buf[256]; + struct passwd *pw; + const char *home; - strcpy(buf,getpwuid(getuid())->pw_dir); - strcat(buf, "/" DEFAULT_FILE); + /* getpwuid() may fail (e.g. no passwd entry for the current uid on a + minimal system): dereferencing the NULL result segfaults. Fall back + to $HOME in that case. */ + pw = getpwuid(getuid()); + if (pw != NULL && pw->pw_dir != NULL && pw->pw_dir[0] != '\0') + home = pw->pw_dir; + else if ((home = getenv("HOME")) == NULL || home[0] == '\0') + fatal("birthday: no passwd entry for uid %d and HOME is not set\n", + (int)getuid()); + + snprintf(buf, sizeof(buf), "%s/%s", home, DEFAULT_FILE); return strdup(buf); #elif defined(DOS)