From patchwork Mon Apr 13 12:28:37 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rasmus Villemoes X-Patchwork-Id: 6182 Received: (qmail 21094 invoked by alias); 13 Apr 2015 12:29:10 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 21056 invoked by uid 89); 13 Apr 2015 12:29:10 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.4 required=5.0 tests=AWL, BAYES_00, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 X-HELO: mail-lb0-f171.google.com X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7r1A9dCUHmLPuTOFqYlvZJKqznMcyscnkcQ2K7Xi0NU=; b=L4MaD73qXSs7Q1iHG3E3CU3yctkijpBO2Rd/PIyA4pQuw13Z+PNRXKKx6t8KAT2zqo OVC8Yc8fTtN+YKKuWhik2adlhg7pzqakrzH16Ogvvz4saQy+yI9t7+54aKNHWzeiI9i5 qDZsjv/azV2vHqmc/sQ6oQeFZd5U15fAaN8uDh4LGchAYlG8i9p/qZlrSRDqWpXLrNJ3 oF9hhNqiENQ9YKl3tVReYZ9PICs+a6MTg++6zqI8Zv3Ym683GtxX2EeheFXRe2iYRKtz fGUlvhmIS0reOtRERVefAW5QRePhyJc9V2uhhX0bO3Ed5fWOc6UTLm+yUyvwsXpE2ARA lFug== X-Gm-Message-State: ALoCoQn0iRUzoELqq/tIVPWdgihEhQcDdyKC55KEb/7gG6ALt/OPqor2S+cRuGqz4euf5nC4R6LH X-Received: by 10.112.57.197 with SMTP id k5mr13454261lbq.102.1428928145655; Mon, 13 Apr 2015 05:29:05 -0700 (PDT) From: Rasmus Villemoes To: libc-alpha@sourceware.org Cc: Jeff King , Rasmus Villemoes Subject: [RFC/PoC 4/4] getdelim: Allow a return value of SSIZE_MAX Date: Mon, 13 Apr 2015 14:28:37 +0200 Message-Id: <1428928117-8643-5-git-send-email-rv@rasmusvillemoes.dk> In-Reply-To: <1428928117-8643-1-git-send-email-rv@rasmusvillemoes.dk> References: <1428928117-8643-1-git-send-email-rv@rasmusvillemoes.dk> The current getdelim function fails with EOVERFLOW if the delimiter is found after exactly SSIZE_MAX characters, but clearly we should succeed and return SSIZE_MAX in that case. We keep >= in the len >= SIZE_MAX - *cur_len comparison, since needed is computed as *cur_len + len + 1. Note that the POSIX 2008 wording for EOVERFLOW ("More than {SSIZE_MAX} characters were read without encountering the delimiter character.") is slightly flawed; it is fixed by . Signed-off-by: Rasmus Villemoes --- libio/iogetdelim.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libio/iogetdelim.c b/libio/iogetdelim.c index 1d20594..e201b9c 100644 --- a/libio/iogetdelim.c +++ b/libio/iogetdelim.c @@ -90,7 +90,7 @@ _IO_getdelim_append (lineptr, n, delimiter, fp, cur_len) if (t != NULL) len = (t - fp->_IO_read_ptr) + 1; if (__glibc_unlikely (len >= SIZE_MAX - *cur_len) || - __glibc_unlikely (len >= SSIZE_MAX - result)) + __glibc_unlikely (len > SSIZE_MAX - result)) { __set_errno (EOVERFLOW); result = -1;