mirror of
https://git.savannah.gnu.org/git/coreutils.git
synced 2026-11-17 18:02:09 +03:00
stdbuf: don’t allocate more than SIZE_MAX / 2
* src/libstdbuf.c (apply_mode): Be more conservative about sizes passed to malloc, since we can’t rely on Gnulib malloc.
This commit is contained in:
1 parent
610725919c
commit
2b54fe97ff
1 file changed
+5
-2
+5
-2
@@ -94,8 +94,11 @@ apply_mode (FILE *stream, char const *stream_name, char const *envvar)
|
||||
return;
|
||||
}
|
||||
|
||||
buf = (size <= ((unsigned long int) -2 < (size_t) -1
|
||||
? (unsigned long int) -2 : (size_t) -1)
|
||||
/* If strtoul might have overflowed or if the size is more than
|
||||
half of size_t range, treat it as an allocation failure.
|
||||
Huge sizes can cause problems with some stdio implementations. */
|
||||
buf = (size <= ((unsigned long int) -2 < (size_t) -1 / 2
|
||||
? (unsigned long int) -2 : (size_t) -1 / 2)
|
||||
? malloc (size) : nullptr);
|
||||
if (!buf)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user