]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
libio: Flush-only _IO_str_overflow must not return EOF (bug 28949)
authorFlorian Weimer <fweimer@redhat.com>
Fri, 18 Mar 2022 20:27:54 +0000 (21:27 +0100)
committerFlorian Weimer <fweimer@redhat.com>
Fri, 18 Mar 2022 20:40:02 +0000 (21:40 +0100)
In general, _IO_str_overflow returns the character passed as an argument
on success.  However, if flush-only operation is requested by passing
EOF, returning EOF looks like an error, and the caller cannot tell
whether the operation was successful or not.

_IO_wstr_overflow had the same bug regarding WEOF.

Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
libio/strops.c
libio/wstrops.c

index 6a9a8846c43c20e52f2c43d8bb7d4d1824b5eb23..1cd0bf6c3d190fd87af83851b77e48eacc3d2387 100644 (file)
@@ -133,7 +133,10 @@ _IO_str_overflow (FILE *fp, int c)
     *fp->_IO_write_ptr++ = (unsigned char) c;
   if (fp->_IO_write_ptr > fp->_IO_read_end)
     fp->_IO_read_end = fp->_IO_write_ptr;
-  return c;
+  if (flush_only)
+    return 0;
+  else
+    return c;
 }
 libc_hidden_def (_IO_str_overflow)
 
index 8e44f86c35a487e2a7dd6082d5b76a1266408c03..2aec314937562abd12d40833b998faf5be63cb51 100644 (file)
@@ -130,7 +130,10 @@ _IO_wstr_overflow (FILE *fp, wint_t c)
     *fp->_wide_data->_IO_write_ptr++ = c;
   if (fp->_wide_data->_IO_write_ptr > fp->_wide_data->_IO_read_end)
     fp->_wide_data->_IO_read_end = fp->_wide_data->_IO_write_ptr;
-  return c;
+  if (flush_only)
+    return 0;
+  else
+    return c;
 }