From patchwork Wed Dec 11 15:13:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tom Tromey X-Patchwork-Id: 36713 Received: (qmail 80848 invoked by alias); 11 Dec 2019 15:13:36 -0000 Mailing-List: contact gdb-patches-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-patches-owner@sourceware.org Delivered-To: mailing list gdb-patches@sourceware.org Received: (qmail 80646 invoked by uid 89); 11 Dec 2019 15:13:36 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-22.3 required=5.0 tests=AWL, BAYES_00, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.1 spammy=xml, XML X-HELO: rock.gnat.com Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 11 Dec 2019 15:13:35 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 5FC2B116299; Wed, 11 Dec 2019 10:13:33 -0500 (EST) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id Ov+YlsUPTz0g; Wed, 11 Dec 2019 10:13:33 -0500 (EST) Received: from murgatroyd.Home (75-166-123-50.hlrn.qwest.net [75.166.123.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by rock.gnat.com (Postfix) with ESMTPSA id 1E60B116286; Wed, 11 Dec 2019 10:13:33 -0500 (EST) From: Tom Tromey To: gdb-patches@sourceware.org Cc: Tom Tromey Subject: [PATCH] Handle CRLF when reading XML on Windows Date: Wed, 11 Dec 2019 08:13:29 -0700 Message-Id: <20191211151329.32021-1-tromey@adacore.com> MIME-Version: 1.0 xml-support.c uses FOPEN_RT, but then reads the entire contents of the file and verifies that the number of bytes read matches the length. This can fail on Windows, where the read will translate line terminators. This patch fixes the bug by changing xml-support.c to use FOPEN_RB. This works because expat correctly handles \r\n line terminators. gdb/ChangeLog 2019-12-11 Tom Tromey * xml-support.c (xml_fetch_content_from_file): Use FOPEN_RB. gdb/testsuite/ChangeLog 2019-12-11 Tom Tromey * gdb.xml/tdesc-arch.exp (set_arch): Add "trans_mode" parameter. Add crlf test. Change-Id: I548438f33eed284dde1de8babf755eaa1a40319d --- gdb/ChangeLog | 4 ++++ gdb/testsuite/ChangeLog | 5 +++++ gdb/testsuite/gdb.xml/tdesc-arch.exp | 14 +++++++++++--- gdb/xml-support.c | 4 ++-- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/gdb/testsuite/gdb.xml/tdesc-arch.exp b/gdb/testsuite/gdb.xml/tdesc-arch.exp index 617ab0616b2..d98e50e5624 100644 --- a/gdb/testsuite/gdb.xml/tdesc-arch.exp +++ b/gdb/testsuite/gdb.xml/tdesc-arch.exp @@ -55,13 +55,16 @@ if { "$arch1" == "" || "$arch2" == "" || "$default_arch" == "" } { # Run these tests twice, once for $arch1 and once for $arch2, to # make sure that the tdesc file overrides the global default. +# TRANS_MODE indicates how newlines should be represented; it should +# be one of the values supported by "fconfigure -translation". -proc set_arch { arch which } { +proc set_arch { arch which trans_mode } { global gdb_prompt global subdir set filename [standard_output_file tdesc-arch.xml] set fd [open $filename w] + fconfigure $fd -translation $trans_mode puts $fd \ " $arch @@ -92,8 +95,13 @@ proc set_arch { arch which } { remote_file host delete $filename } -set_arch $arch1 first -set_arch $arch2 second +set_arch $arch1 first lf +set_arch $arch2 second lf + +with_test_prefix crlf { + set_arch $arch1 first crlf + set_arch $arch2 second crlf +} # Check an invalid architecture setting. set filename [standard_output_file tdesc-arch.xml] diff --git a/gdb/xml-support.c b/gdb/xml-support.c index 915be76066d..6f877d43d97 100644 --- a/gdb/xml-support.c +++ b/gdb/xml-support.c @@ -979,11 +979,11 @@ xml_fetch_content_from_file (const char *filename, void *baton) if (fullname == NULL) malloc_failure (0); - file = gdb_fopen_cloexec (fullname, FOPEN_RT); + file = gdb_fopen_cloexec (fullname, FOPEN_RB); xfree (fullname); } else - file = gdb_fopen_cloexec (filename, FOPEN_RT); + file = gdb_fopen_cloexec (filename, FOPEN_RB); if (file == NULL) return {};