diff options
| author | Sébastien Dailly <sebastien@dailly.me> | 2026-11-22 21:15:17 +0100 |
|---|---|---|
| committer | Sébastien Dailly <sebastien@dailly.me> | 2026-11-22 21:15:17 +0100 |
| commit | bbaa6afe687e28cd996a5e6a051561062513d565 (patch) | |
| tree | 087a26752ad238e910e57985b2c30dc6c2af71e3 /patches/birthday | |
| parent | b3e549a2dbf1b74c3ea7b1e4321c20953fc2ce11 (diff) | |
Added birthday package from debianmain
Diffstat (limited to 'patches/birthday')
| -rw-r--r-- | patches/birthday/0001-deffname-fallback-to-HOME.patch | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/patches/birthday/0001-deffname-fallback-to-HOME.patch b/patches/birthday/0001-deffname-fallback-to-HOME.patch new file mode 100644 index 0000000..02381d9 --- /dev/null +++ b/patches/birthday/0001-deffname-fallback-to-HOME.patch @@ -0,0 +1,34 @@ +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) |
