summaryrefslogtreecommitdiffstats
path: root/patches/procps-3.2.8/generic/35_path_max.dpatch
blob: 9ab50a012f2018a98832b9bd0b6881765ae9dcb7 (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#! /bin/sh /usr/share/dpatch/dpatch-run
## 35_path_max.dpatch by Madhusudan.C.S <madhusudancs@gmail.com>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Uses alloc instead of fixed PATH_MAX value #496274

@DPATCH@
diff -urNad procps-3.2.7~/proc/readproc.c procps-3.2.7/proc/readproc.c
--- procps-3.2.7~/proc/readproc.c	2008-09-09 15:01:09.000000000 +1000
+++ procps-3.2.7/proc/readproc.c	2008-09-09 15:01:36.000000000 +1000
@@ -1034,7 +1034,7 @@
  * and filled out proc_t structure.
  */
 proc_t * get_proc_stats(pid_t pid, proc_t *p) {
-	static char path[PATH_MAX], sbuf[1024];
+	static char path[32], sbuf[1024];
 	struct stat statbuf;
 
 	sprintf(path, "/proc/%d", pid);
diff -urNad procps-3.2.7~/pwdx.c procps-3.2.7/pwdx.c
--- procps-3.2.7~/pwdx.c	2006-06-17 19:29:06.000000000 +1000
+++ procps-3.2.7/pwdx.c 	2009-03-11 19:56:58.466099226 +0100
@@ -35,7 +35,6 @@
 
 int main(int argc, char* argv[])
 {
-     char buf[PATH_MAX+1];
      regex_t re;
      int i;
 
@@ -59,6 +58,7 @@
 
      for (i = 1; i < argc; i++) {
           if (regexec(&re, argv[i], 0, NULL, 0) != 0) {
+               char buf[27 + strlen (argv[i]) + 1];  // Constant 27 is the length of the error string "pwdx: ... "
                snprintf(buf, sizeof buf, "pwdx: invalid process id: %s\n", argv[i]);
                die(buf);
           }
@@ -68,9 +68,13 @@
 
      regfree(&re);
 
+     int alloclen = 128;
+     char *pathbuf = malloc(alloclen);
+
      for (i = 1; i < argc; i++) {
-          char * s = buf;
+          char * s;
           int len;
+          char buf[10 + strlen(argv[i]) + 1]; // Constant 10 is the length of strings "/proc/" + "/cwd" + 1
           
           // At this point, all arguments are in the form /proc/nnnn
           // or nnnn, so a simple check based on the first char is
@@ -83,13 +87,21 @@
           // buf contains /proc/nnnn/cwd symlink name on entry, the
           // target of that symlink on return
-          if ((len = readlink(buf, buf, PATH_MAX)) < 0) {
+          while ((len = readlink(buf, pathbuf, alloclen)) == alloclen) {
+               alloclen *= 2;
+               pathbuf = realloc(pathbuf, alloclen);
+          }
+
+          if (len < 0) {
                s = strerror(errno == ENOENT ? ESRCH : errno);
           } else {
-               buf[len] = 0;
+               pathbuf[len] = 0;
+               s = pathbuf;
           }

           printf("%s: %s\n", argv[i], s);
      }

+     free(pathbuf);
+
      return 0;
 }