mirror of
https://sourceware.org/git/glibc.git
synced 2025-09-04 03:22:14 +03:00
Fix reading loginuid file in getlogin{,_r}.
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
2010-04-08 Ulrich Drepper <drepper@redhat.com>
|
2010-04-08 Ulrich Drepper <drepper@redhat.com>
|
||||||
|
|
||||||
|
* sysdeps/unix/sysv/linux/getlogin_r.c (__getlogin_r_loginuid): When
|
||||||
|
reading the loginuid file use a buffer which is always large enough.
|
||||||
|
NUL-terminate the string.
|
||||||
|
|
||||||
* malloc/malloc.c (_int_malloc): Return NULL if printing error message
|
* malloc/malloc.c (_int_malloc): Return NULL if printing error message
|
||||||
returns.
|
returns.
|
||||||
|
|
||||||
|
@@ -37,13 +37,20 @@ __getlogin_r_loginuid (name, namesize)
|
|||||||
if (fd == -1)
|
if (fd == -1)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
ssize_t n = TEMP_FAILURE_RETRY (read_not_cancel (fd, name, namesize));
|
/* We are reading a 32-bit number. 12 bytes are enough for the text
|
||||||
|
representation. If not, something is wrong. */
|
||||||
|
char uidbuf[12];
|
||||||
|
ssize_t n = TEMP_FAILURE_RETRY (read_not_cancel (fd, uidbuf,
|
||||||
|
sizeof (uidbuf)));
|
||||||
close_not_cancel_no_status (fd);
|
close_not_cancel_no_status (fd);
|
||||||
|
|
||||||
uid_t uid;
|
uid_t uid;
|
||||||
char *endp;
|
char *endp;
|
||||||
if (n <= 0
|
if (n <= 0
|
||||||
|| (uid = strtoul (name, &endp, 10), endp == name || *endp != '\0'))
|
|| n == sizeof (uidbuf)
|
||||||
|
|| (uidbuf[n] = '\0',
|
||||||
|
uid = strtoul (uidbuf, &endp, 10),
|
||||||
|
endp == uidbuf || *endp != '\0'))
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
size_t buflen = 1024;
|
size_t buflen = 1024;
|
||||||
@@ -84,8 +91,9 @@ __getlogin_r_loginuid (name, namesize)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Return the login name of the user, or NULL if it can't be determined.
|
/* Return at most NAME_LEN characters of the login name of the user in NAME.
|
||||||
The returned pointer, if not NULL, is good only until the next call. */
|
If it cannot be determined or some other error occurred, return the error
|
||||||
|
code. Otherwise return 0. */
|
||||||
|
|
||||||
int
|
int
|
||||||
getlogin_r (name, namesize)
|
getlogin_r (name, namesize)
|
||||||
|
Reference in New Issue
Block a user