Package: sysvinit / 2.88dsf-41+deb7u1

72_path_max.patch Patch series | download
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
Purpose: Don't use undefined PATH_MAX
Fixes:   Compilation on platforms not having PATH_MAX such as GNU/Hurd
Authur:  Roger Leigh
Status:  Not yet submitted upstream
---
--- a/startpar/proc.c	2012-01-28 11:37:09.325271380 +0000
+++ b/startpar/proc.c	2012-01-28 11:54:43.268729900 +0000
@@ -109,23 +109,38 @@
     char *name = (char*)0;
     struct dirent *dent;
     int fd;
+    char *path = (char *)0;
+    size_t allocpathlen = 0;
 
     fd = dirfd(dir);
     rewinddir(dir);
     while ((dent = readdir(dir))) {
-	char path[PATH_MAX];
 	struct stat st;
+	size_t pathlen = 0;
 	if (fstatat(fd, dent->d_name, &st, 0) < 0)
 	    continue;
 	if (!S_ISCHR(st.st_mode))
 	    continue;
 	if (comparedev != st.st_rdev)
 	    continue;
-	if ((size_t)snprintf(path, sizeof(path), "/dev/%s", dent->d_name) >= sizeof(path))
+	/* Space for d_name, /dev/ and nul */
+	pathlen = strlen(dent->d_name) + 6;
+	if (pathlen > allocpathlen) {
+	    char *newpath = realloc(path, sizeof(char) * pathlen);
+	    if (newpath) {
+		path = newpath;
+	        allocpathlen = pathlen;
+	    }
+	}
+	if (path == NULL)
+	    continue;
+	if ((size_t)snprintf(path, pathlen, "/dev/%s", dent->d_name) >= allocpathlen)
 	    continue;
 	name = realpath(path, NULL);
 	break;
     }
+
+    free(path);
     return name;
 }