From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 43A463858D1E for ; Thu, 22 Dec 2022 21:22:53 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 43A463858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671744172; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=rNqlRhqCnK1SI4jqTZky9/1AmEku7OVGd77XGI1drQQ=; b=gQ0Ytc2p+dY4e9kcDqJwOhOK7xOz0AKiT4DuQJV4oVsPWZa8vlUvJ04i/49x07db7s9MsI MOwwD8hOoVBIFT/4e5BOXMXAtYh/w8L1h1sBD5ypDHKRHj/6Y6VhNuLY/kaS0KEH/Yawa/ H5A+IynCyzHOeN/E0VC2xmW6jUDrbkI= Received: from mail-il1-f198.google.com (mail-il1-f198.google.com [209.85.166.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-523-Krs77z1VNRC-1hEPiwIkFg-1; Thu, 22 Dec 2022 16:22:51 -0500 X-MC-Unique: Krs77z1VNRC-1hEPiwIkFg-1 Received: by mail-il1-f198.google.com with SMTP id y6-20020a056e02178600b0030bc8cb4312so1694950ilu.1 for ; Thu, 22 Dec 2022 13:22:51 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:organization:from:references :cc:to:content-language:subject:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=rNqlRhqCnK1SI4jqTZky9/1AmEku7OVGd77XGI1drQQ=; b=OHS96yzcwzQ8PH70Q9jrqhA8RUbp+FVgecKeOLZDZuKhOY27q6kND73vYroDCSrkPi K4xF8mMNSo2kRW3E9qpQ8u6ukgR2OgZdhOoXiblUhpMjnTJVUBVi7RYPk0bUoDm/5KF4 XGx1u4VIr3i2dnqsxgwZ9dBqrEg1tQeclC/A/fqrGU40g11rleSCswscsXGU9FNKQ4WT MptLZvipFgUScCFobWDctYvoFG+0dSx68bC1bai9+kUjp9QIE2JZubn55AolZYv7rX2T o0S7IsfLZR5KLm87o65Bxg9Jpri5irQwaCHliz1P88NAVlmaGD2Z/thliysJjPAQ/xH/ BxFw== X-Gm-Message-State: AFqh2kqTmNfSfVPpZgC9t61gf4o0bs/hH1xeEOc+ybuVGfASvzyneGaS bTXkD55w3CYTmnSIq0nI4R57EBC33QAObGWiDwYxyu6DSMqZOOV5KZM4Q64rXNYZ1fdSJF0b0WL WezKTQXMCHHQVIpRtrM2k X-Received: by 2002:a92:1943:0:b0:30b:d29b:8068 with SMTP id e3-20020a921943000000b0030bd29b8068mr4359735ilm.29.1671744170656; Thu, 22 Dec 2022 13:22:50 -0800 (PST) X-Google-Smtp-Source: AMrXdXuA5ADkVuX7sgGSsHt1Bs/fd9+UYQZmJ54stcs7xPDLT8vJwYNN5IF8nt7YgpCX8y/RTr8Hvw== X-Received: by 2002:a92:1943:0:b0:30b:d29b:8068 with SMTP id e3-20020a921943000000b0030bd29b8068mr4359732ilm.29.1671744170386; Thu, 22 Dec 2022 13:22:50 -0800 (PST) Received: from [192.168.0.241] (192-0-145-146.cpe.teksavvy.com. [192.0.145.146]) by smtp.gmail.com with ESMTPSA id r22-20020a02b116000000b00363ec4dcaacsm394442jah.22.2022.12.22.13.22.49 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 22 Dec 2022 13:22:49 -0800 (PST) Message-ID: Date: Thu, 22 Dec 2022 16:22:48 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.1 Subject: Re: [PATCH] getdelim: ensure error indicator is set on error (bug 29917) To: Andreas Schwab Cc: libc-alpha@sourceware.org References: <60addddd-0c0f-a0e5-f2ad-de7e7a12a854@redhat.com> <27d0eba1-3c9a-75b6-4681-bafbf13b5e31@redhat.com> From: Carlos O'Donell Organization: Red Hat In-Reply-To: X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,KAM_SHORT,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 12/21/22 04:29, Andreas Schwab wrote: > POSIX requires that getdelim and getline set the error indicator on the > stream when an error occured, in addition to setting errno. LGTM. Thank you. Reviewed-by: Carlos O'Donell > --- > libio/Makefile | 2 +- > libio/iogetdelim.c | 16 +++++++++++----- > libio/tst-getdelim.c | 36 ++++++++++++++++++++++++++++++++++++ > 3 files changed, 48 insertions(+), 6 deletions(-) > create mode 100644 libio/tst-getdelim.c > > diff --git a/libio/Makefile b/libio/Makefile > index 64398ab1ee..9c69a85c87 100644 > --- a/libio/Makefile > +++ b/libio/Makefile > @@ -66,7 +66,7 @@ tests = tst_swprintf tst_wprintf tst_swscanf tst_wscanf tst_getwc tst_putwc \ > tst-fwrite-error tst-ftell-partial-wide tst-ftell-active-handler \ > tst-ftell-append tst-fputws tst-bz22415 tst-fgetc-after-eof \ > tst-sprintf-ub tst-sprintf-chk-ub tst-bz24051 tst-bz24153 \ > - tst-wfile-sync tst-bz28828 > + tst-wfile-sync tst-bz28828 tst-getdelim > > tests-internal = tst-vtables tst-vtables-interposed > > 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; > } > diff --git a/libio/tst-getdelim.c b/libio/tst-getdelim.c > new file mode 100644 > index 0000000000..1def193e8d > --- /dev/null > +++ b/libio/tst-getdelim.c > @@ -0,0 +1,36 @@ > +/* Check that getdelim sets error indicator on error (BZ #29917) > + > + Copyright (C) 2022 Free Software Foundation, Inc. > + This file is part of the GNU C Library. > + > + The GNU C Library is free software; you can redistribute it and/or > + modify it under the terms of the GNU Lesser General Public > + License as published by the Free Software Foundation; either > + version 2.1 of the License, or (at your option) any later version. > + > + The GNU C Library is distributed in the hope that it will be useful, > + but WITHOUT ANY WARRANTY; without even the implied warranty of > + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU > + Lesser General Public License for more details. > + > + You should have received a copy of the GNU Lesser General Public > + License along with the GNU C Library; if not, see > + . */ > + > +#include > +#include > + > +#include > + > +static int > +do_test (void) > +{ > + clearerr (stdin); > + TEST_VERIFY (getdelim (0, 0, '\n', stdin) == -1); OK. s/EOF/-1/g is corrected. Thanks. > + TEST_VERIFY (ferror (stdin) != 0); > + TEST_VERIFY (errno == EINVAL); > + > + return 0; > +} > + > +#include -- Cheers, Carlos.