aboutsummaryrefslogtreecommitdiff
path: root/binutils
diff options
context:
space:
mode:
authorEli Zaretskii <eliz@gnu.org>2021-01-28 14:57:33 +0000
committerNick Clifton <nickc@redhat.com>2021-01-28 14:57:33 +0000
commitcc3edc52747fd8b184ee48f1b0cc1ac0aca7832e (patch)
tree8ab99dd07fd5c274ea4f7fada5a7f79898f18acc /binutils
parent53e556e5b45e3d8fda25be3623883a0952c0c716 (diff)
downloadgdb-cc3edc52747fd8b184ee48f1b0cc1ac0aca7832e.zip
gdb-cc3edc52747fd8b184ee48f1b0cc1ac0aca7832e.tar.gz
gdb-cc3edc52747fd8b184ee48f1b0cc1ac0aca7832e.tar.bz2
Improve windres's handling of pathnames containing special characters on Windows platforms.
PR 4356 * windres.c (quot): Use double quotes to protect strings on Windows platforms.
Diffstat (limited to 'binutils')
-rw-r--r--binutils/ChangeLog6
-rw-r--r--binutils/windres.c31
2 files changed, 34 insertions, 3 deletions
diff --git a/binutils/ChangeLog b/binutils/ChangeLog
index c02a0eef..5cdeb41 100644
--- a/binutils/ChangeLog
+++ b/binutils/ChangeLog
@@ -1,5 +1,11 @@
2021-01-28 Eli Zaretskii <eliz@gnu.org>
+ PR 4356
+ * windres.c (quot): Use double quotes to protect strings on
+ Windows platforms.
+
+2021-01-28 Eli Zaretskii <eliz@gnu.org>
+
PR 27252
* bucomm.c (get_file_size): Add code to handle /dev/null on
Windows systems.
diff --git a/binutils/windres.c b/binutils/windres.c
index 41d1e92..b35661c 100644
--- a/binutils/windres.c
+++ b/binutils/windres.c
@@ -703,19 +703,44 @@ quot (const char *string)
const char *src;
char *dest;
- if ((buflen < slen * 2 + 2) || ! buf)
+ if ((buflen < slen * 2 + 3) || ! buf)
{
- buflen = slen * 2 + 2;
+ buflen = slen * 2 + 3;
free (buf);
buf = (char *) xmalloc (buflen);
}
- for (src=string, dest=buf; *src; src++, dest++)
+#if defined (_WIN32) && !defined (__CYGWIN__)
+ /* For Windows shells, quote "like this". */
+ {
+ bfd_boolean quoted = FALSE;
+
+ dest = buf;
+ if (strchr (string, ' '))
+ {
+ quoted = TRUE;
+ *dest++ = '"';
+ }
+
+ for (src = string; *src; src++, dest++)
+ {
+ /* Escape-protect embedded double quotes. */
+ if (quoted && *src == '"')
+ *dest++ = '\\';
+ *dest = *src;
+ }
+
+ if (quoted)
+ *dest++ = '"';
+ }
+#else
+ for (src = string, dest = buf; *src; src++, dest++)
{
if (*src == '(' || *src == ')' || *src == ' ')
*dest++ = '\\';
*dest = *src;
}
+#endif
*dest = 0;
return buf;
}