aboutsummaryrefslogtreecommitdiff
path: root/games/joy2key/home_not_set_segfault.patch
blob: 0e0fb08c816fae8148c1f3d8d3377d4cad0d29a5 (plain)
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
Author: Jonathan Niehof <jtniehof@gmail.com>
Subject: Fix segfault if $HOME not set and -config passed
Bug-Debian: https://bugs.debian.org/716582
Forwarded: https://sourceforge.net/p/joy2key/patches/5/
Last-Update: 2013-07-13

--- a/joy2key.c
+++ b/joy2key.c
@@ -386,6 +386,7 @@
     FILE *file;
     int rcargc;
     char *rcargv[255], line[255];
+    char *homedir;
     
     for(i=1; i<argc; i++)
     {
@@ -442,9 +443,15 @@
 			}
 			if(strcmp(rcfile,DEFAULT_RCFILE) == 0)
 			{
-				x=strlen(getenv("HOME")) + strlen(rcfile) + 2;
+			        homedir=getenv("HOME");
+				if(homedir==NULL)
+				{
+				        printf("No home directory; cannot open default rc file\n");
+					exit(1);
+				}
+				x=strlen(homedir) + strlen(rcfile) + 2;
 				rcfile=(char*)malloc(x);
-				sprintf(rcfile, "%s/%s", getenv("HOME"), DEFAULT_RCFILE);
+				sprintf(rcfile, "%s/%s", homedir, DEFAULT_RCFILE);
 			}
 			if((file=fopen(rcfile, "r"))==NULL)
 			{