]> git.ipfire.org Git - people/pmueller/ipfire-2.x.git/blob - src/patches/glibc/glibc-rh621959.patch
Merge remote-tracking branch 'origin/next' into thirteen
[people/pmueller/ipfire-2.x.git] / src / patches / glibc / glibc-rh621959.patch
1 2010-08-06 Ulrich Drepper <drepper@redhat.com>
2
3 * sysdeps/unix/sysv/linux/getlogin_r.c (__getlogin_r_loginuid):
4 Also fail if tpwd after pwuid call is NULL.
5
6 2010-06-21 Andreas Schwab <schwab@redhat.com>
7
8 * sysdeps/unix/sysv/linux/getlogin_r.c (__getlogin_r_loginuid):
9 Restore proper fallback handling.
10
11 2010-06-19 Ulrich Drepper <drepper@redhat.com>
12
13 * sysdeps/unix/sysv/linux/getlogin_r.c (__getlogin_r_loginuid): Handle
14 OOM in getpwuid_r correctly. Return error number when the caller
15 should return, otherwise -1.
16 (getlogin_r): Adjust to return also for result of __getlogin_r_loginuid
17 call returning > 0 value.
18 * sysdeps/unix/sysv/linux/getlogin.c (getlogin): Likewise.
19
20 Index: glibc-2.12-2-gc4ccff1/sysdeps/unix/sysv/linux/getlogin.c
21 ===================================================================
22 --- glibc-2.12-2-gc4ccff1.orig/sysdeps/unix/sysv/linux/getlogin.c
23 +++ glibc-2.12-2-gc4ccff1/sysdeps/unix/sysv/linux/getlogin.c
24 @@ -32,8 +32,9 @@
25 char *
26 getlogin (void)
27 {
28 - if (__getlogin_r_loginuid (name, sizeof (name)) == 0)
29 - return name;
30 + int res = __getlogin_r_loginuid (name, sizeof (name));
31 + if (res >= 0)
32 + return res == 0 ? name : NULL;
33
34 return getlogin_fd0 ();
35 }
36 Index: glibc-2.12-2-gc4ccff1/sysdeps/unix/sysv/linux/getlogin_r.c
37 ===================================================================
38 --- glibc-2.12-2-gc4ccff1.orig/sysdeps/unix/sysv/linux/getlogin_r.c
39 +++ glibc-2.12-2-gc4ccff1/sysdeps/unix/sysv/linux/getlogin_r.c
40 @@ -27,6 +27,10 @@ static int getlogin_r_fd0 (char *name, s
41 #undef getlogin_r
42
43
44 +/* Try to determine login name from /proc/self/loginuid and return 0
45 + if successful. If /proc/self/loginuid cannot be read return -1.
46 + Otherwise return the error number. */
47 +
48 int
49 attribute_hidden
50 __getlogin_r_loginuid (name, namesize)
51 @@ -35,7 +39,7 @@ __getlogin_r_loginuid (name, namesize)
52 {
53 int fd = open_not_cancel_2 ("/proc/self/loginuid", O_RDONLY);
54 if (fd == -1)
55 - return 1;
56 + return -1;
57
58 /* We are reading a 32-bit number. 12 bytes are enough for the text
59 representation. If not, something is wrong. */
60 @@ -51,37 +55,38 @@ __getlogin_r_loginuid (name, namesize)
61 || (uidbuf[n] = '\0',
62 uid = strtoul (uidbuf, &endp, 10),
63 endp == uidbuf || *endp != '\0'))
64 - return 1;
65 + return -1;
66
67 size_t buflen = 1024;
68 char *buf = alloca (buflen);
69 bool use_malloc = false;
70 struct passwd pwd;
71 struct passwd *tpwd;
72 + int result = 0;
73 int res;
74
75 - while ((res = __getpwuid_r (uid, &pwd, buf, buflen, &tpwd)) != 0)
76 + while ((res = __getpwuid_r (uid, &pwd, buf, buflen, &tpwd)) == ERANGE)
77 if (__libc_use_alloca (2 * buflen))
78 - extend_alloca (buf, buflen, 2 * buflen);
79 + buf = extend_alloca (buf, buflen, 2 * buflen);
80 else
81 {
82 buflen *= 2;
83 char *newp = realloc (use_malloc ? buf : NULL, buflen);
84 if (newp == NULL)
85 {
86 - fail:
87 - if (use_malloc)
88 - free (buf);
89 - return 1;
90 + result = ENOMEM;
91 + goto out;
92 }
93 buf = newp;
94 use_malloc = true;
95 }
96
97 - if (tpwd == NULL)
98 - goto fail;
99 + if (res != 0 || tpwd == NULL)
100 + {
101 + result = -1;
102 + goto out;
103 + }
104
105 - int result = 0;
106 size_t needed = strlen (pwd.pw_name) + 1;
107 if (needed > namesize)
108 {
109 @@ -109,8 +114,9 @@ getlogin_r (name, namesize)
110 char *name;
111 size_t namesize;
112 {
113 - if (__getlogin_r_loginuid (name, namesize) == 0)
114 - return 0;
115 + int res = __getlogin_r_loginuid (name, namesize);
116 + if (res >= 0)
117 + return res;
118
119 return getlogin_r_fd0 (name, namesize);
120 }