bug-binutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Bug binutils/27843] New: windres quoting of backslashes and double quot


From: martin at martin dot st
Subject: [Bug binutils/27843] New: windres quoting of backslashes and double quotes is lacking
Date: Mon, 10 May 2021 20:49:02 +0000

https://sourceware.org/bugzilla/show_bug.cgi?id=27843

            Bug ID: 27843
           Summary: windres quoting of backslashes and double quotes is
                    lacking
           Product: binutils
           Version: unspecified
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: binutils
          Assignee: unassigned at sourceware dot org
          Reporter: martin at martin dot st
  Target Milestone: ---

Given a rc file like this:

$ cat test.rc
STRINGTABLE {
  1 STRING
}

Normally, if one were to provide the definition of STRING via a command line
option when preprocessing C, one would specify it as -DSTRING=\"foo\" on the
command line, so that the tool receives the argument as -DSTRING="foo", and
substitutes "foo".

So far, across all versions (modern at least) of windres, the quotes aren't
re-escaped properly. So currently, the only way of getting this to work is to
double escape the backslashes, into this form, that works on both unix and
windows:

$ x86_64-w64-mingw32-windres test.rc test.res -DSTRING=\\\"foo\\\" -v
Using `x86_64-w64-mingw32-gcc -E -xc -DRC_INVOKED -DSTRING=\"foo\" test.rc'

Currently (after cc3edc52747fd8b184ee48f1b0cc1ac0aca7832e, up until the revert
mishap in the current master version) it actually does work without double
escaping (on windows only), if the string otherwise happens to contain a space:

> windres.exe test.rc test.res "-DSTRING=\"fo o\"" -v
Using `mingw64\bin\gcc -E -xc -DRC_INVOKED -D"STRING=\"fo o\"" test.rc'

But without a space:

> windres.exe test.rc test.res -DSTRING=\"foo\" -v
Using `mingw64\bin\gcc -E -xc -DRC_INVOKED -DSTRING="foo" test.rc'
Using popen to read preprocessor output
windres.exe: test.rc:2: syntax error


So double quotes need to be escaped, on all platforms, even if the string
doesn't contain spaces.


Fixing this is going to break GNU libiconv, which contains a script for doing
double escaping of arguments to windres:
https://git.savannah.gnu.org/gitweb/?p=libiconv.git;a=blob;f=windows/windres-options;h=779fddec305d1e78f1e5c3123683b3c380e4a82e;hb=4b1a76b8e7f718fb23eb1a48cd1be208cfff6c2a
And the script is unconditionally called with the --escape option for enabling
the escaping:
https://git.savannah.gnu.org/gitweb/?p=libiconv.git;a=blob;f=src/Makefile.in;h=7035316ae52a38fd7515e065a63a5c14ee7f4efb;hb=4b1a76b8e7f718fb23eb1a48cd1be208cfff6c2a#l87

If this is fixed, I don't offhand see a god way of fixing iconv to be buildable
both with old and new versions of windres at the same time, short of either
trying both quoting forms or just rewriting the use of those macros to avoid
needing to pass quoted strings on the command line.


Additionally, once the quotes are escaped/quoted properly, other tricky strings
that may need more work for quoting (with different quoting styles for windows
and unix) are strings that contain single or double backslashes (not directly
before a double quote). (I don't believe there's real use of this in the wild,
but would be good to handle correctly for consistency.)

-- 
You are receiving this mail because:
You are on the CC list for the bug.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]