From patchwork Thu Mar 17 19:28:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Florian Weimer X-Patchwork-Id: 52063 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8956F384387A for ; Thu, 17 Mar 2022 19:30:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8956F384387A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1647545417; bh=0gTG6nzU/d4BSZnF2+twVziG5pOl+LKPOzyH1h7tK7Y=; h=To:Subject:In-Reply-To:References:Date:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=UnHRYOcH1sl7B2BXQDjwjxkPQIBhfTj7SuKKlH84lo840ozM/WhAzalXNOiVQ2JIY hukgH4qhEDXD8u2yocHcxS9fT1yMXVslkkTF1c2buAnaKgmToJrarNAKZgfoKbaYc+ Al7Ly0SluF0DkVKzGHOAjLdL4KMl0ajP10yhx1jY= X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org 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 7A5693861C74 for ; Thu, 17 Mar 2022 19:28:23 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7A5693861C74 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-517-lzsH8LJEPSiHAGna_HmTKw-1; Thu, 17 Mar 2022 15:28:22 -0400 X-MC-Unique: lzsH8LJEPSiHAGna_HmTKw-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.rdu2.redhat.com [10.11.54.1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id D938C8001EA for ; Thu, 17 Mar 2022 19:28:21 +0000 (UTC) Received: from oldenburg.str.redhat.com (unknown [10.39.192.88]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 3F9E140F9D53 for ; Thu, 17 Mar 2022 19:28:21 +0000 (UTC) To: libc-alpha@sourceware.org Subject: [PATCH 02/26] libio: Flush-only _IO_str_overflow must not return EOF (bug 28949) In-Reply-To: References: X-From-Line: ff81d93901347fa0c78de22f0f9d6f8283ed627c Mon Sep 17 00:00:00 2001 Message-Id: Date: Thu, 17 Mar 2022 20:28:19 +0100 User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.11.54.1 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.1 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Florian Weimer via Libc-alpha From: Florian Weimer Reply-To: Florian Weimer Errors-To: libc-alpha-bounces+patchwork=sourceware.org@sourceware.org Sender: "Libc-alpha" 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 --- 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; }