[02/26] libio: Flush-only _IO_str_overflow must not return EOF (bug 28949)

Message ID ff81d93901347fa0c78de22f0f9d6f8283ed627c.1647544751.git.fweimer@redhat.com
State Committed
Commit 88ed43ff0cf2561481de7cba00686386794515d6
Headers
Series vfprintf rework to remove vtables |

Checks

Context Check Description
dj/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Florian Weimer March 17, 2022, 7:28 p.m. UTC
  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.
---
 libio/strops.c  | 5 ++++-
 libio/wstrops.c | 5 ++++-
 2 files changed, 8 insertions(+), 2 deletions(-)
  

Comments

Adhemerval Zanella March 18, 2022, 6:11 p.m. UTC | #1
On 17/03/2022 16:28, Florian Weimer via Libc-alpha wrote:
> 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.

LGTM, thanks.

Reviewed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> ---
>  libio/strops.c  | 5 ++++-
>  libio/wstrops.c | 5 ++++-
>  2 files changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/libio/strops.c b/libio/strops.c
> index 6a9a8846c4..1cd0bf6c3d 100644
> --- a/libio/strops.c
> +++ b/libio/strops.c
> @@ -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)
>  
> diff --git a/libio/wstrops.c b/libio/wstrops.c
> index 8e44f86c35..2aec314937 100644
> --- a/libio/wstrops.c
> +++ b/libio/wstrops.c
> @@ -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;
>  }
>  
>
  

Patch

diff --git a/libio/strops.c b/libio/strops.c
index 6a9a8846c4..1cd0bf6c3d 100644
--- a/libio/strops.c
+++ b/libio/strops.c
@@ -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)
 
diff --git a/libio/wstrops.c b/libio/wstrops.c
index 8e44f86c35..2aec314937 100644
--- a/libio/wstrops.c
+++ b/libio/wstrops.c
@@ -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;
 }