File: 07_segfault_no_home.patch

package info (click to toggle)
billard-gl 1.75-18
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 11,572 kB
  • sloc: cpp: 10,496; makefile: 155
file content (48 lines) | stat: -rw-r--r-- 1,620 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
Description: billard-gl tries to get the HOME dir but doesn't fail gracefully 
  if it is not set in the environment.  This patch addresses that.
Author: Barry deFreese <bdefreese@debian.org>
Debian-Bug: http://bugs.debian.org/715681
Index: billard-gl-1.75/src/KommandoZeilenParameter.cpp
===================================================================
--- billard-gl-1.75.orig/src/KommandoZeilenParameter.cpp	2013-08-09 11:52:05.000000000 -0400
+++ billard-gl-1.75/src/KommandoZeilenParameter.cpp	2013-08-09 20:25:45.906456954 -0400
@@ -2,6 +2,9 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <pwd.h>
 #include "Namen.h"
 #include "KommandoZeilenParameter.h"
 
@@ -9,7 +12,13 @@
   FILE *f;
 #ifndef _WIN32
   char dateiname[512];
-  snprintf(dateiname,sizeof(dateiname),"%s/.BillardGL.conf.v7",getenv("HOME"));
+  const char *homedir = getenv("HOME");
+  if (!homedir) {
+    struct passwd *pw;
+    pw = getpwuid(getuid());
+    homedir = pw->pw_dir;
+  }
+  snprintf(dateiname,sizeof(dateiname),"%s/.BillardGL.conf.v7",homedir);
   f=fopen(dateiname,"w+");
 #endif
 #ifdef _WIN32
@@ -66,7 +75,13 @@
   FILE *f;
 #ifndef _WIN32
   char dateiname[512];
-  snprintf(dateiname,sizeof(dateiname),"%s/.BillardGL.conf.v7",getenv("HOME"));
+  const char *homedir = getenv("HOME");
+  if (!homedir) {
+    struct passwd *pw;
+    pw = getpwuid(getuid());
+    homedir = pw->pw_dir;
+  }
+  snprintf(dateiname,sizeof(dateiname),"%s/.BillardGL.conf.v7",homedir);
   f=fopen(dateiname,"r");
 #endif
 #ifdef _WIN32