Package: sudo / 1.8.19p1-2.1

use-proc-self-consistently-on-linux.diff 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

# HG changeset patch
# User Todd C. Miller <Todd.Miller@courtesan.com>
# Date 1496162651 21600
# Node ID 6f3d9816541ba84055ae5aec6ff9d9523c2a96f3
# Parent  98ef2ef47aba10f6b83904dca4d446c4b8f24987
Use /proc/self consistently on Linux.  As far as I know, only AIX
doesn't support /proc/self.

diff -r 98ef2ef47aba -r 6f3d9816541b src/ttyname.c
--- a/src/ttyname.c	Mon May 29 14:36:35 2017 -0600
+++ b/src/ttyname.c	Tue May 30 10:44:11 2017 -0600
@@ -451,7 +451,8 @@
 char *
 get_process_ttyname(char *name, size_t namelen)
 {
-    char path[PATH_MAX], *line = NULL;
+    const char path[] = "/proc/self/stat";
+    char *line = NULL;
     char *ret = NULL;
     size_t linesize = 0;
     int serrno = errno;
@@ -459,8 +460,7 @@
     FILE *fp;
     debug_decl(get_process_ttyname, SUDO_DEBUG_UTIL)
 
-    /* Try to determine the tty from tty_nr in /proc/pid/stat. */
-    snprintf(path, sizeof(path), "/proc/%u/stat", (unsigned int)getpid());
+    /* Try to determine the tty from tty_nr in /proc/self/stat. */
     if ((fp = fopen(path, "r")) != NULL) {
 	len = getline(&line, &linesize, fp);
 	fclose(fp);