public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
From: Carlos O'Donell <carlos@redhat.com>
To: Andreas Schwab <schwab@suse.de>, libc-alpha@sourceware.org
Subject: Re: [PATCH] getdelim: ensure error indicator is set on error (bug 29917)
Date: Mon, 19 Dec 2022 09:59:06 -0500	[thread overview]
Message-ID: <60addddd-0c0f-a0e5-f2ad-de7e7a12a854@redhat.com> (raw)
In-Reply-To: <mvmzgbjpoll.fsf@suse.de>

On 12/19/22 07:25, Andreas Schwab via Libc-alpha wrote:
> POSIX requires that getdelim and getline set the error indicator on the
> stream when an error occured, in addition to setting errno.

May we please write a test case that validates this requirement?

We don't need to test all the error scenarios, but at least one
of them to validate would be helpful.

Thanks.

> ---
>  libio/iogetdelim.c | 16 +++++++++++-----
>  1 file changed, 11 insertions(+), 5 deletions(-)
> 
> diff --git a/libio/iogetdelim.c b/libio/iogetdelim.c
> index b6c4c07b45..591526e9c1 100644
> --- a/libio/iogetdelim.c
> +++ b/libio/iogetdelim.c
> @@ -43,11 +43,6 @@ __getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp)
>    ssize_t cur_len = 0;
>    ssize_t len;
>  
> -  if (lineptr == NULL || n == NULL)
> -    {
> -      __set_errno (EINVAL);
> -      return -1;
> -    }
>    CHECK_FILE (fp, -1);
>    _IO_acquire_lock (fp);
>    if (_IO_ferror_unlocked (fp))
> @@ -56,12 +51,21 @@ __getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp)
>        goto unlock_return;
>      }
>  
> +  if (lineptr == NULL || n == NULL)
> +    {
> +      __set_errno (EINVAL);
> +      fseterr_unlocked (fp);
> +      result = -1;
> +      goto unlock_return;
> +    }
> +
>    if (*lineptr == NULL || *n == 0)
>      {
>        *n = 120;
>        *lineptr = (char *) malloc (*n);
>        if (*lineptr == NULL)
>  	{
> +	  fseterr_unlocked (fp);
>  	  result = -1;
>  	  goto unlock_return;
>  	}
> @@ -88,6 +92,7 @@ __getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp)
>        if (__glibc_unlikely (len >= SSIZE_MAX - cur_len))
>  	{
>  	  __set_errno (EOVERFLOW);
> +	  fseterr_unlocked (fp);
>  	  result = -1;
>  	  goto unlock_return;
>  	}
> @@ -102,6 +107,7 @@ __getdelim (char **lineptr, size_t *n, int delimiter, FILE *fp)
>  	  new_lineptr = (char *) realloc (*lineptr, needed);
>  	  if (new_lineptr == NULL)
>  	    {
> +	      fseterr_unlocked (fp);
>  	      result = -1;
>  	      goto unlock_return;
>  	    }

-- 
Cheers,
Carlos.


  reply	other threads:[~2022-12-19 14:59 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-12-19 12:25 Andreas Schwab
2022-12-19 14:59 ` Carlos O'Donell [this message]
2022-12-19 16:01   ` Andreas Schwab
2022-12-19 17:47     ` Carlos O'Donell
2022-12-21  9:29       ` Andreas Schwab
2022-12-22 21:22         ` Carlos O'Donell

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=60addddd-0c0f-a0e5-f2ad-de7e7a12a854@redhat.com \
    --to=carlos@redhat.com \
    --cc=libc-alpha@sourceware.org \
    --cc=schwab@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).