mirror of
https://sourceware.org/git/glibc.git
synced 2024-11-08 14:20:07 +00:00
(__getcwd_chk): Always fail if the buffer is too small.
This commit is contained in:
parent
61062f5630
commit
8b8b797292
@ -24,8 +24,8 @@
|
||||
char *
|
||||
__getcwd_chk (char *buf, size_t size, size_t buflen)
|
||||
{
|
||||
char *res = __getcwd (buf, MIN (size, buflen));
|
||||
if (res == NULL && errno == ERANGE && size > buflen)
|
||||
if (size > buflen)
|
||||
__chk_fail ();
|
||||
return res;
|
||||
|
||||
return __getcwd (buf, size);
|
||||
}
|
||||
|
@ -23,11 +23,8 @@
|
||||
ssize_t
|
||||
__pread64_chk (int fd, void *buf, size_t nbytes, off64_t offset, size_t buflen)
|
||||
{
|
||||
/* In case NBYTES is greater than BUFLEN, we read BUFLEN+1 bytes.
|
||||
This might overflow the buffer but the damage is reduced to just
|
||||
one byte. And the program will terminate right away. */
|
||||
ssize_t n = __pread64 (fd, buf, offset, MIN (nbytes, buflen + 1));
|
||||
if (n > 0 && (size_t) n > buflen)
|
||||
if (nbytes > buflen)
|
||||
__chk_fail ();
|
||||
return n;
|
||||
|
||||
return __pread64 (fd, buf, offset, MIN (nbytes, buflen + 1));
|
||||
}
|
||||
|
@ -27,15 +27,12 @@
|
||||
ssize_t
|
||||
__readlink_chk (const char *path, void *buf, size_t len, size_t buflen)
|
||||
{
|
||||
/* In case LEN is greater than BUFLEN, we read BUFLEN+1 bytes.
|
||||
This might overflow the buffer but the damage is reduced to just
|
||||
one byte. And the program will terminate right away. */
|
||||
#ifdef HAVE_INLINED_SYSCALLS
|
||||
int n = INLINE_SYSCALL (readlink, 3, path, buf, MIN (len, buflen + 1));
|
||||
#else
|
||||
int n = __readlink (path, buf, MIN (len, buflen + 1));
|
||||
#endif
|
||||
if (n > 0 && (size_t) n > buflen)
|
||||
if (len > buflen)
|
||||
__chk_fail ();
|
||||
return n;
|
||||
|
||||
#ifdef HAVE_INLINED_SYSCALLS
|
||||
return INLINE_SYSCALL (readlink, 3, path, buf, MIN (len, buflen + 1));
|
||||
#else
|
||||
return __readlink (path, buf, MIN (len, buflen + 1));
|
||||
#endif
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user