|
|
4999bf |
2010-08-06 Ulrich Drepper <drepper@redhat.com>
|
|
|
4999bf |
|
|
|
4999bf |
* sysdeps/unix/sysv/linux/getlogin_r.c (__getlogin_r_loginuid):
|
|
|
4999bf |
Also fail if tpwd after pwuid call is NULL.
|
|
|
4999bf |
|
|
|
4999bf |
2010-06-21 Andreas Schwab <schwab@redhat.com>
|
|
|
4999bf |
|
|
|
4999bf |
* sysdeps/unix/sysv/linux/getlogin_r.c (__getlogin_r_loginuid):
|
|
|
4999bf |
Restore proper fallback handling.
|
|
|
4999bf |
|
|
|
4999bf |
2010-06-19 Ulrich Drepper <drepper@redhat.com>
|
|
|
4999bf |
|
|
|
4999bf |
* sysdeps/unix/sysv/linux/getlogin_r.c (__getlogin_r_loginuid): Handle
|
|
|
4999bf |
OOM in getpwuid_r correctly. Return error number when the caller
|
|
|
4999bf |
should return, otherwise -1.
|
|
|
4999bf |
(getlogin_r): Adjust to return also for result of __getlogin_r_loginuid
|
|
|
4999bf |
call returning > 0 value.
|
|
|
4999bf |
* sysdeps/unix/sysv/linux/getlogin.c (getlogin): Likewise.
|
|
|
4999bf |
|
|
|
4999bf |
Index: glibc-2.12-2-gc4ccff1/sysdeps/unix/sysv/linux/getlogin.c
|
|
|
4999bf |
===================================================================
|
|
|
4999bf |
--- glibc-2.12-2-gc4ccff1.orig/sysdeps/unix/sysv/linux/getlogin.c
|
|
|
4999bf |
+++ glibc-2.12-2-gc4ccff1/sysdeps/unix/sysv/linux/getlogin.c
|
|
|
4999bf |
@@ -32,8 +32,9 @@
|
|
|
4999bf |
char *
|
|
|
4999bf |
getlogin (void)
|
|
|
4999bf |
{
|
|
|
4999bf |
- if (__getlogin_r_loginuid (name, sizeof (name)) == 0)
|
|
|
4999bf |
- return name;
|
|
|
4999bf |
+ int res = __getlogin_r_loginuid (name, sizeof (name));
|
|
|
4999bf |
+ if (res >= 0)
|
|
|
4999bf |
+ return res == 0 ? name : NULL;
|
|
|
4999bf |
|
|
|
4999bf |
return getlogin_fd0 ();
|
|
|
4999bf |
}
|
|
|
4999bf |
Index: glibc-2.12-2-gc4ccff1/sysdeps/unix/sysv/linux/getlogin_r.c
|
|
|
4999bf |
===================================================================
|
|
|
4999bf |
--- glibc-2.12-2-gc4ccff1.orig/sysdeps/unix/sysv/linux/getlogin_r.c
|
|
|
4999bf |
+++ glibc-2.12-2-gc4ccff1/sysdeps/unix/sysv/linux/getlogin_r.c
|
|
|
4999bf |
@@ -27,6 +27,10 @@ static int getlogin_r_fd0 (char *name, s
|
|
|
4999bf |
#undef getlogin_r
|
|
|
4999bf |
|
|
|
4999bf |
|
|
|
4999bf |
+/* Try to determine login name from /proc/self/loginuid and return 0
|
|
|
4999bf |
+ if successful. If /proc/self/loginuid cannot be read return -1.
|
|
|
4999bf |
+ Otherwise return the error number. */
|
|
|
4999bf |
+
|
|
|
4999bf |
int
|
|
|
4999bf |
attribute_hidden
|
|
|
4999bf |
__getlogin_r_loginuid (name, namesize)
|
|
|
4999bf |
@@ -35,7 +39,7 @@ __getlogin_r_loginuid (name, namesize)
|
|
|
4999bf |
{
|
|
|
4999bf |
int fd = open_not_cancel_2 ("/proc/self/loginuid", O_RDONLY);
|
|
|
4999bf |
if (fd == -1)
|
|
|
4999bf |
- return 1;
|
|
|
4999bf |
+ return -1;
|
|
|
4999bf |
|
|
|
4999bf |
/* We are reading a 32-bit number. 12 bytes are enough for the text
|
|
|
4999bf |
representation. If not, something is wrong. */
|
|
|
4999bf |
@@ -51,37 +55,38 @@ __getlogin_r_loginuid (name, namesize)
|
|
|
4999bf |
|| (uidbuf[n] = '\0',
|
|
|
4999bf |
uid = strtoul (uidbuf, &endp, 10),
|
|
|
4999bf |
endp == uidbuf || *endp != '\0'))
|
|
|
4999bf |
- return 1;
|
|
|
4999bf |
+ return -1;
|
|
|
4999bf |
|
|
|
4999bf |
size_t buflen = 1024;
|
|
|
4999bf |
char *buf = alloca (buflen);
|
|
|
4999bf |
bool use_malloc = false;
|
|
|
4999bf |
struct passwd pwd;
|
|
|
4999bf |
struct passwd *tpwd;
|
|
|
4999bf |
+ int result = 0;
|
|
|
4999bf |
int res;
|
|
|
4999bf |
|
|
|
4999bf |
- while ((res = __getpwuid_r (uid, &pwd, buf, buflen, &tpwd)) != 0)
|
|
|
4999bf |
+ while ((res = __getpwuid_r (uid, &pwd, buf, buflen, &tpwd)) == ERANGE)
|
|
|
4999bf |
if (__libc_use_alloca (2 * buflen))
|
|
|
4999bf |
- extend_alloca (buf, buflen, 2 * buflen);
|
|
|
4999bf |
+ buf = extend_alloca (buf, buflen, 2 * buflen);
|
|
|
4999bf |
else
|
|
|
4999bf |
{
|
|
|
4999bf |
buflen *= 2;
|
|
|
4999bf |
char *newp = realloc (use_malloc ? buf : NULL, buflen);
|
|
|
4999bf |
if (newp == NULL)
|
|
|
4999bf |
{
|
|
|
4999bf |
- fail:
|
|
|
4999bf |
- if (use_malloc)
|
|
|
4999bf |
- free (buf);
|
|
|
4999bf |
- return 1;
|
|
|
4999bf |
+ result = ENOMEM;
|
|
|
4999bf |
+ goto out;
|
|
|
4999bf |
}
|
|
|
4999bf |
buf = newp;
|
|
|
4999bf |
use_malloc = true;
|
|
|
4999bf |
}
|
|
|
4999bf |
|
|
|
4999bf |
- if (tpwd == NULL)
|
|
|
4999bf |
- goto fail;
|
|
|
4999bf |
+ if (res != 0 || tpwd == NULL)
|
|
|
4999bf |
+ {
|
|
|
4999bf |
+ result = -1;
|
|
|
4999bf |
+ goto out;
|
|
|
4999bf |
+ }
|
|
|
4999bf |
|
|
|
4999bf |
- int result = 0;
|
|
|
4999bf |
size_t needed = strlen (pwd.pw_name) + 1;
|
|
|
4999bf |
if (needed > namesize)
|
|
|
4999bf |
{
|
|
|
4999bf |
@@ -109,8 +114,9 @@ getlogin_r (name, namesize)
|
|
|
4999bf |
char *name;
|
|
|
4999bf |
size_t namesize;
|
|
|
4999bf |
{
|
|
|
4999bf |
- if (__getlogin_r_loginuid (name, namesize) == 0)
|
|
|
4999bf |
- return 0;
|
|
|
4999bf |
+ int res = __getlogin_r_loginuid (name, namesize);
|
|
|
4999bf |
+ if (res >= 0)
|
|
|
4999bf |
+ return res;
|
|
|
4999bf |
|
|
|
4999bf |
return getlogin_r_fd0 (name, namesize);
|
|
|
4999bf |
}
|