summaryrefslogtreecommitdiff
path: root/patches/birthday
diff options
context:
space:
mode:
Diffstat (limited to 'patches/birthday')
-rw-r--r--patches/birthday/0001-deffname-fallback-to-HOME.patch34
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)