summaryrefslogtreecommitdiff
path: root/stdio-common/vfprintf.c
diff options
context:
space:
mode:
authorEric Biggers <ebiggers3@gmail.com>2013-10-11 22:29:38 +0530
committerSiddhesh Poyarekar <siddhesh@redhat.com>2013-10-11 22:29:38 +0530
commit3d110c7c6e6549bd4124fce49cdc672f9e449799 (patch)
tree465a14f8a2e1c8e58f470c2550a524fff481228e /stdio-common/vfprintf.c
parent75b4202ab03337edb37536e3d9470a48a04c9341 (diff)
downloadglibc-3d110c7c6e6549bd4124fce49cdc672f9e449799.tar.gz
Fix fwrite() reading beyond end of buffer in error path
Partially revert commits 2b766585f9b4ffabeef2f36200c275976b93f2c7 and de2fd463b1c0310d75084b6d774fb974075a4ad9, which were intended to fix BZ#11741 but caused another, likely worse bug, namely that fwrite() and fputs() could, in an error path, read data beyond the end of the specified buffer, and potentially even write this data to the file. Fix BZ#11741 properly by checking the return value from _IO_padn() in stdio-common/vfprintf.c.
Diffstat (limited to 'stdio-common/vfprintf.c')
-rw-r--r--stdio-common/vfprintf.c12
1 files changed, 6 insertions, 6 deletions
diff --git a/stdio-common/vfprintf.c b/stdio-common/vfprintf.c
index fb22f6969e..8cd7a85b21 100644
--- a/stdio-common/vfprintf.c
+++ b/stdio-common/vfprintf.c
@@ -90,13 +90,13 @@
do { \
if (width > 0) \
{ \
- unsigned int d = _IO_padn (s, (Padchar), width); \
- if (__glibc_unlikely (d == EOF)) \
+ _IO_ssize_t written = _IO_padn (s, (Padchar), width); \
+ if (__glibc_unlikely (written != width)) \
{ \
done = -1; \
goto all_done; \
} \
- done_add (d); \
+ done_add (written); \
} \
} while (0)
# define PUTC(C, F) _IO_putc_unlocked (C, F)
@@ -119,13 +119,13 @@
do { \
if (width > 0) \
{ \
- unsigned int d = _IO_wpadn (s, (Padchar), width); \
- if (__glibc_unlikely (d == EOF)) \
+ _IO_ssize_t written = _IO_wpadn (s, (Padchar), width); \
+ if (__glibc_unlikely (written != width)) \
{ \
done = -1; \
goto all_done; \
} \
- done_add (d); \
+ done_add (written); \
} \
} while (0)
# define PUTC(C, F) _IO_putwc_unlocked (C, F)