From patchwork Wed May 15 12:48:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Schwab X-Patchwork-Id: 1100031 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=sourceware.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=libc-alpha-return-101992-incoming=patchwork.ozlabs.org@sourceware.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; secure) header.d=sourceware.org header.i=@sourceware.org header.b="oZDyvzGU"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 453vVj3XLRz9s9N for ; Wed, 15 May 2019 22:48:29 +1000 (AEST) DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:mime-version :content-type; q=dns; s=default; b=ZZS8ABk2kKq8i8ZlwpqwTVrLi9TbV jXu9TWg4p7vLqQjwA9j6iZMl1b7ggovdDj6WsYi8nGa1Lba4VxYfCQiTAU5VOQoM eia8CCwcI0uiVcrGu01+ZD0o9LWU8mdsICM4gXl4XYFNyDfQ7ybn0fmJlFQdP+2d yNw8mokdXXoqIk= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id :list-unsubscribe:list-subscribe:list-archive:list-post :list-help:sender:from:to:subject:date:message-id:mime-version :content-type; s=default; bh=rJkQ5ceKCWWPD1ZAjpsNjUmbNwI=; b=oZD yvzGUbpKe2TjL4jC3sBW7WzDocJxEm65K03TRfhJaBc5DyI4TZd20cdiNONErRX/ 0rYxxRpQ5IyBRDMCfXHIqxGS1vjnHB/bz91W6xPWeY8HphJUf/rFx7MRkTQUcdrI stCRLeC2yvf3xhvHJOtsCG31keRo1zoXQoYIihJc= Received: (qmail 64734 invoked by alias); 15 May 2019 12:48:23 -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 32702 invoked by uid 89); 15 May 2019 12:48:16 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-15.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, KAM_SHORT, SPF_PASS autolearn=ham version=3.3.1 spammy= X-HELO: mx1.suse.de From: Andreas Schwab To: libc-alpha@sourceware.org Subject: [PATCH] Fix crash in _IO_wfile_sync (bug 20568) X-Yow: Are we live or on tape? Date: Wed, 15 May 2019 14:48:03 +0200 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux) MIME-Version: 1.0 [BZ #20568] * libio/wfileops.c (_IO_wfile_sync): Correct last argument to __codecvt_do_length. * libio/Makefile (tests): Add tst-wfile-sync. ($(objpfx)tst-wfile-sync.out): Depend on $(gen-locales). * libio/tst-wfile-sync.c: New file. * libio/tst-wfile-sync.input: New file. --- libio/Makefile | 4 +++- libio/tst-wfile-sync.c | 35 +++++++++++++++++++++++++++++++++++ libio/tst-wfile-sync.input | 1 + libio/wfileops.c | 4 ++-- 4 files changed, 41 insertions(+), 3 deletions(-) create mode 100644 libio/tst-wfile-sync.c create mode 100644 libio/tst-wfile-sync.input diff --git a/libio/Makefile b/libio/Makefile index 95b91084dd..a5236c7042 100644 --- a/libio/Makefile +++ b/libio/Makefile @@ -65,7 +65,8 @@ tests = tst_swprintf tst_wprintf tst_swscanf tst_wscanf tst_getwc tst_putwc \ tst-setvbuf1 tst-popen1 tst-fgetwc bug-wsetpos tst-fseek \ 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-sprintf-ub tst-sprintf-chk-ub tst-bz24051 tst-bz24153 \ + tst-wfile-sync tests-internal = tst-vtables tst-vtables-interposed tst-readline @@ -212,6 +213,7 @@ $(objpfx)tst-ungetwc1.out: $(gen-locales) $(objpfx)tst-ungetwc2.out: $(gen-locales) $(objpfx)tst-widetext.out: $(gen-locales) $(objpfx)tst_wprintf2.out: $(gen-locales) +$(objpfx)tst-wfile-sync.out: $(gen-locales) endif $(objpfx)test-freopen.out: test-freopen.sh $(objpfx)test-freopen diff --git a/libio/tst-wfile-sync.c b/libio/tst-wfile-sync.c new file mode 100644 index 0000000000..e1f621ede7 --- /dev/null +++ b/libio/tst-wfile-sync.c @@ -0,0 +1,35 @@ +/* Test that _IO_wfile_sync does not crash (bug 20568). + Copyright (C) 2016-2019 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 +#include + +static int +do_test (void) +{ + TEST_VERIFY_EXIT (setlocale (LC_ALL, "de_DE.UTF-8") != NULL); + TEST_VERIFY_EXIT (fgetwc (stdin) != WEOF); + /* This calls _IO_wfile_sync. */ + TEST_VERIFY_EXIT (setvbuf (stdin, NULL, _IONBF, 0) == 0); + + return 0; +} + +#include diff --git a/libio/tst-wfile-sync.input b/libio/tst-wfile-sync.input new file mode 100644 index 0000000000..12d0958f7a --- /dev/null +++ b/libio/tst-wfile-sync.input @@ -0,0 +1 @@ +This is a test of _IO_wfile_sync. diff --git a/libio/wfileops.c b/libio/wfileops.c index 0367643703..42aaf5e855 100644 --- a/libio/wfileops.c +++ b/libio/wfileops.c @@ -508,11 +508,11 @@ _IO_wfile_sync (FILE *fp) generate the wide characters up to the current reading position. */ int nread; - + size_t wnread = fp->_wide_data->_IO_read_ptr - fp->_wide_data->_IO_read_base; fp->_wide_data->_IO_state = fp->_wide_data->_IO_last_state; nread = (*cv->__codecvt_do_length) (cv, &fp->_wide_data->_IO_state, fp->_IO_read_base, - fp->_IO_read_end, delta); + fp->_IO_read_end, wnread); fp->_IO_read_ptr = fp->_IO_read_base + nread; delta = -(fp->_IO_read_end - fp->_IO_read_base - nread); }