diff mbox series

buildsys: Preserve arguments passed on

Message ID 1553221569-2164-1-git-send-email-joe@benden.us
State New
Headers show
Series buildsys: Preserve arguments passed on | expand

Commit Message

Joseph Benden March 22, 2019, 2:26 a.m. UTC
This patch ensures all arguments are quoted, during command-line
construction.

This fixes compilation where spaces occur within the arguments.

Additional Information:

  https://github.com/openwrt/openwrt/pull/1620

Signed-off-by: Joseph Benden <joe@benden.us>
---
 bin/Makefile.in | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Bernhard Reutner-Fischer April 4, 2019, 3:04 p.m. UTC | #1
On Fri, 22 Mar 2019 at 03:36, Joseph Benden <joe@benden.us> wrote:
>
> This patch ensures all arguments are quoted, during command-line
> construction.
>
> This fixes compilation where spaces occur within the arguments.

Can you give me an example please?
g++-uc -DFOO="BAR BAZ" -c ... ?

TIA,
Joseph Benden April 4, 2019, 4:41 p.m. UTC | #2
On 4/4/19 8:04 AM, Bernhard Reutner-Fischer wrote:
> On Fri, 22 Mar 2019 at 03:36, Joseph Benden <joe@benden.us> wrote:
>> This patch ensures all arguments are quoted, during command-line
>> construction.
>>
>> This fixes compilation where spaces occur within the arguments.
> Can you give me an example please?
> g++-uc -DFOO="BAR BAZ" -c ... ?
>
> TIA,
>
Hi,

Yes.

The problem was found in arguments sent from autotools. An example
compile would use the line below. The first problematic item is
-DPACKAGE_STRING in the line, along with the need for quotes to be
preserved in the line (else preprocessor fails):

/bin/bash ../../libtool  --tag=CC   --mode=compile powerpc-openwrt-linux-musl-gcc -DPACKAGE_NAME=\"aircrack-ng\" -DPACKAGE_TARNAME=\"aircrack-ng\" -DPACKAGE_VERSION=\"1.5.2\" -DPACKAGE_STRING=\"aircrack-ng\ 1.5.2\" -DPACKAGE_BUGREPORT=\"https://forum.aircrack-ng.org\" -DPACKAGE_URL=\"\" -DPACKAGE=\"aircrack-ng\" -DVERSION=\"1.5.2\" -DSTDC_HEADERS=1 -DHAVE_SYS_TYPES_H=1 -DHAVE_SYS_STAT_H=1 -DHAVE_STDLIB_H=1 -DHAVE_STRING_H=1 -DHAVE_MEMORY_H=1 -DHAVE_STRINGS_H=1 -DHAVE_INTTYPES_H=1 -DHAVE_STDINT_H=1 -DHAVE_UNISTD_H=1 -DHAVE_DLFCN_H=1 -DLT_OBJDIR=\".libs/\" -D_REVISION=\"1.5.2\" -DHAVE_OPENSSL_CRYPTO_H=1 -DHAVE_OPENSSL_CMAC_H=1 -DHAVE_OPENSSL_CMAC_H=1 -DHAVE_PCAP_H=1 -DHAVE_PCAP=1 -DHAVE_PCRE=1 -DHAVE_ZLIB=1 -DHAVE_PTHREAD_PRIO_INHERIT=1 -D_REENTRANT=1 -DHAVE_POSIX_MEMALIGN=1 -DHAVE_SYS_AUXV_H=1 -DHAS_AUXV=1 -DCACHELINE_SIZE=64 -DHAVE_SYS_AUXV_H=1 -DHAS_AUXV=1 -DCACHELINE_SIZE=64 -I.  -I../.. -I../../src/include -I../../src   -I/data/bowl-builder/powerpc_8540/build/sdk/staging_d
 ir/target-powerpc_8540_musl/usr/include -I/data/bowl-builder/powerpc_8540/build/sdk/staging_dir/target-powerpc_8540_musl/include -I/data/bowl-builder/powerpc_8540/build/sdk/staging_dir/toolchain-powerpc_8540_gcc-7.4.0_musl/usr/include -I/data/bowl-builder/powerpc_8540/build/sdk/staging_dir/toolchain-powerpc_8540_gcc-7.4.0_musl/include/fortify -I/data/bowl-builder/powerpc_8540/build/sdk/staging_dir/toolchain-powerpc_8540_gcc-7.4.0_musl/include  -I/data/bowl-builder/powerpc_8540/build/sdk/staging_dir/target-powerpc_8540_musl/usr/include -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -pthread   -Wall -std=gnu99 -fno-strict-aliasing -Wpointer-arith -Wstrict-overflow=2 -Wstrict-prototypes -fvisibility=hidden -Wno-unused-but-set-variable -Wno-array-bounds -Os -pipe -mcpu=8540 -fno-caller-saves -fno-plt -fhonour-copts -Wno-error=unused-but-set-variable -Wno-error=unused-result -msoft-float -iremap/data/bowl-builder/powerpc_8540/build/sdk/build_dir/target-powerpc_8540_musl/aircrack-ng
 -1.5.2:aircrack-ng-1.5.2 -Wformat -Werror=format-security -fstack-protector -D_FORTIFY_SOURCE=1 -Wl,-z,now -Wl,-z,relro -Wall -Wextra -ffunction-sections -fdata-sections  -MT libaircrack_crypto_la-memory.lo -MD -MP -MF .deps/libaircrack_crypto_la-memory.Tpo -c -o libaircrack_crypto_la-memory.lo `test -f 'memory.c' || echo './'`memory.c

Thanks,
-Joe
Bernhard Reutner-Fischer April 5, 2019, 9:58 a.m. UTC | #3
On Thu, 4 Apr 2019 09:41:52 -0700
Joseph Benden <joe@benden.us> wrote:

> On 4/4/19 8:04 AM, Bernhard Reutner-Fischer wrote:
> > On Fri, 22 Mar 2019 at 03:36, Joseph Benden <joe@benden.us> wrote:  
> >> This patch ensures all arguments are quoted, during command-line
> >> construction.
> >>
> >> This fixes compilation where spaces occur within the arguments.  
> > Can you give me an example please?
> > g++-uc -DFOO="BAR BAZ" -c ... ?
> >
> > TIA,
> >  
> Hi,
> 
> Yes.

I think we can simply avoid the whole issue.
May i ask you to try the attached patch instead?
TIA,
diff --git a/bin/Makefile.in b/bin/Makefile.in
index 8d11316..9ea2f06 100644
--- a/bin/Makefile.in
+++ b/bin/Makefile.in
@@ -32,26 +32,20 @@ define do_wrapper
 	$(Q)echo 'WRAPPER_LIBS="$(strip $(LIBS))"' >> $@.tmp
 	$(Q)echo '' >> $@.tmp
 	$(Q)echo 'WRAPPER_INCLIB="Y"' >> $@.tmp
-	$(Q)echo 'while [ -n "$$1" ]' >> $@.tmp
+	$(Q)echo 'for arg' >> $@.tmp
 	$(Q)echo 'do' >> $@.tmp
-	$(Q)echo '	WRAPPER_OPTIONS="$$WRAPPER_OPTIONS $$1"' >> $@.tmp
-	$(Q)echo '	if [ "$$1" = "-c" -o "$$1" = "-E" -o "$$1" = "-S" ]' >> $@.tmp
-	$(Q)echo '	then' >> $@.tmp
-	$(Q)echo '		WRAPPER_INCLIB="N"' >> $@.tmp
-	$(Q)echo '	fi' >> $@.tmp
-	$(Q)echo '	if [ "$$1" = "-static" -a "$$WRAPPER_LIBS" != "$(strip $(STATIC_LIBS))" ]' >> $@.tmp
-	$(Q)echo '	then' >> $@.tmp
-	$(Q)echo '		WRAPPER_LIBS="$(strip $(STATIC_LIBS))"' >> $@.tmp
-	$(Q)echo '	fi' >> $@.tmp
-	$(Q)echo '	shift' >> $@.tmp
+	$(Q)echo '	case "$$arg" in' >> $@.tmp
+	$(Q)echo '	-c|-E|-S) WRAPPER_INCLIB="N" ;;' >> $@.tmp
+	$(Q)echo '	-static) [ "$$WRAPPER_LIBS" != "$(strip $(STATIC_LIBS))" ] && WRAPPER_LIBS="$(strip $(STATIC_LIBS))" ;;' >> $@.tmp
+	$(Q)echo '	esac' >> $@.tmp
 	$(Q)echo 'done' >> $@.tmp
 	$(Q)echo 'if [ "$$WRAPPER_INCLIB" = "Y" ]' >> $@.tmp
 	$(Q)echo 'then' >> $@.tmp
 	$(Q)echo '	WRAPPER_OPTIONS="$$WRAPPER_OPTIONS -nodefaultlibs $$WRAPPER_LIBDIR -l$(LNAME) $$WRAPPER_LIBS"' >> $@.tmp
 	$(Q)echo 'fi' >> $@.tmp
 	$(Q)echo '' >> $@.tmp
-	$(Q)echo '[ -n "$$V" ] && [ $$V -gt 1 ] && echo $(CXX) $(GEN_CFLAGS) $(GEN_CXXFLAGS) $(EH_CXXFLAGS) $$WRAPPER_INCLUDEDIR $$WRAPPER_OPTIONS' >> $@.tmp
-	$(Q)echo 'exec $(CXX) $(GEN_CFLAGS) $(GEN_CXXFLAGS) $(EH_CXXFLAGS) $$WRAPPER_INCLUDEDIR $$WRAPPER_OPTIONS' >> $@.tmp
+	$(Q)echo '[ -n "$$V" ] && [ $$V -gt 1 ] && echo $(CXX) $(GEN_CFLAGS) $(GEN_CXXFLAGS) $(EH_CXXFLAGS) $$WRAPPER_INCLUDEDIR "$$@" $$WRAPPER_OPTIONS' >> $@.tmp
+	$(Q)echo 'exec $(CXX) $(GEN_CFLAGS) $(GEN_CXXFLAGS) $(EH_CXXFLAGS) $$WRAPPER_INCLUDEDIR "$$@" $$WRAPPER_OPTIONS' >> $@.tmp
 	$(Q)echo '' >> $@.tmp
 	$(Q)chmod 0755 $@.tmp
 	$(Q)mv $@.tmp $@
Joseph Benden April 5, 2019, 3:53 p.m. UTC | #4
On 4/5/19 2:58 AM, Bernhard Reutner-Fischer wrote:
> On Thu, 4 Apr 2019 09:41:52 -0700
> Joseph Benden <joe@benden.us> wrote:
>
>> On 4/4/19 8:04 AM, Bernhard Reutner-Fischer wrote:
>>> On Fri, 22 Mar 2019 at 03:36, Joseph Benden <joe@benden.us> wrote:  
>>>> This patch ensures all arguments are quoted, during command-line
>>>> construction.
>>>>
>>>> This fixes compilation where spaces occur within the arguments.  
>>> Can you give me an example please?
>>> g++-uc -DFOO="BAR BAZ" -c ... ?
>>>
>>> TIA,
>>>  
>> Hi,
>>
>> Yes.
> I think we can simply avoid the whole issue.
> May i ask you to try the attached patch instead?
> TIA,

I do not have a simple way of testing, as I am depending on (slightly
outdated) uclibc++ inside of OpenWrt.

However, since arguments are now expanded via the shell, it should work
just fine - better in fact. I think your patch should go in.

Thanks!!
-Joe
diff mbox series

Patch

diff --git a/bin/Makefile.in b/bin/Makefile.in
index 8d11316..17e0ae5 100644
--- a/bin/Makefile.in
+++ b/bin/Makefile.in
@@ -34,7 +34,7 @@  define do_wrapper
 	$(Q)echo 'WRAPPER_INCLIB="Y"' >> $@.tmp
 	$(Q)echo 'while [ -n "$$1" ]' >> $@.tmp
 	$(Q)echo 'do' >> $@.tmp
-	$(Q)echo '	WRAPPER_OPTIONS="$$WRAPPER_OPTIONS $$1"' >> $@.tmp
+	$(Q)echo '	WRAPPER_OPTIONS="$$WRAPPER_OPTIONS '"'"'$$1'"'"'"' >> $@.tmp
 	$(Q)echo '	if [ "$$1" = "-c" -o "$$1" = "-E" -o "$$1" = "-S" ]' >> $@.tmp
 	$(Q)echo '	then' >> $@.tmp
 	$(Q)echo '		WRAPPER_INCLIB="N"' >> $@.tmp
@@ -51,7 +51,7 @@  define do_wrapper
 	$(Q)echo 'fi' >> $@.tmp
 	$(Q)echo '' >> $@.tmp
 	$(Q)echo '[ -n "$$V" ] && [ $$V -gt 1 ] && echo $(CXX) $(GEN_CFLAGS) $(GEN_CXXFLAGS) $(EH_CXXFLAGS) $$WRAPPER_INCLUDEDIR $$WRAPPER_OPTIONS' >> $@.tmp
-	$(Q)echo 'exec $(CXX) $(GEN_CFLAGS) $(GEN_CXXFLAGS) $(EH_CXXFLAGS) $$WRAPPER_INCLUDEDIR $$WRAPPER_OPTIONS' >> $@.tmp
+	$(Q)echo 'eval $(CXX) $(GEN_CFLAGS) $(GEN_CXXFLAGS) $(EH_CXXFLAGS) "$$WRAPPER_INCLUDEDIR" "$$WRAPPER_OPTIONS"' >> $@.tmp
 	$(Q)echo '' >> $@.tmp
 	$(Q)chmod 0755 $@.tmp
 	$(Q)mv $@.tmp $@