public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Handle CRLF when reading XML on Windows
@ 2019-12-11 15:13 Tom Tromey
  2019-12-19 17:00 ` Tom Tromey
  0 siblings, 1 reply; 2+ messages in thread
From: Tom Tromey @ 2019-12-11 15:13 UTC (permalink / raw)
  To: gdb-patches; +Cc: Tom Tromey

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  <tromey@adacore.com>

	* xml-support.c (xml_fetch_content_from_file): Use FOPEN_RB.

gdb/testsuite/ChangeLog
2019-12-11  Tom Tromey  <tromey@adacore.com>

	* 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 \
 	"<target>
 	    <architecture>$arch</architecture>
@@ -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 {};
-- 
2.21.0

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] Handle CRLF when reading XML on Windows
  2019-12-11 15:13 [PATCH] Handle CRLF when reading XML on Windows Tom Tromey
@ 2019-12-19 17:00 ` Tom Tromey
  0 siblings, 0 replies; 2+ messages in thread
From: Tom Tromey @ 2019-12-19 17:00 UTC (permalink / raw)
  To: Tom Tromey; +Cc: gdb-patches

>>>>> "Tom" == Tom Tromey <tromey@adacore.com> writes:

Tom> gdb/ChangeLog
Tom> 2019-12-11  Tom Tromey  <tromey@adacore.com>

Tom> 	* xml-support.c (xml_fetch_content_from_file): Use FOPEN_RB.

I'm checking this in.

Tom

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2019-12-19 17:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-11 15:13 [PATCH] Handle CRLF when reading XML on Windows Tom Tromey
2019-12-19 17:00 ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).