From d558e30ab3a5932fe0625f01e18be4bfebb12729 Mon Sep 17 00:00:00 2001 From: William Pitcock Date: Tue, 7 Feb 2017 10:24:54 -0600 Subject: [PATCH] libpkgconf: argvsplit: quoting logic was simplified too much --- Makefile.am | 2 ++ libpkgconf/argvsplit.c | 11 +++++++++++ tests/lib1/fragment-quoting-2.pc | 10 ++++++++++ tests/lib1/fragment-quoting-3.pc | 10 ++++++++++ tests/parser.sh | 20 +++++++++++++++++++- 5 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 tests/lib1/fragment-quoting-2.pc create mode 100644 tests/lib1/fragment-quoting-3.pc diff --git a/Makefile.am b/Makefile.am index 0c0576d..1fb61a6 100644 --- a/Makefile.am +++ b/Makefile.am @@ -66,6 +66,8 @@ EXTRA_DIST = pkg.m4 \ tests/lib1/flag-order-3.pc \ tests/lib1/variable-whitespace.pc \ tests/lib1/fragment-quoting.pc \ + tests/lib1/fragment-quoting-2.pc \ + tests/lib1/fragment-quoting-3.pc \ tests/test_env.sh \ $(test_scripts) \ doc/conf.py \ diff --git a/libpkgconf/argvsplit.c b/libpkgconf/argvsplit.c index cded5f7..209afdf 100644 --- a/libpkgconf/argvsplit.c +++ b/libpkgconf/argvsplit.c @@ -64,6 +64,7 @@ pkgconf_argv_split(const char *src, int *argc, char ***argv) int argc_count = 0; int argv_size = 5; char quote = 0; + bool in_single_quotes = false; src_iter = src; dst_iter = buf; @@ -111,6 +112,16 @@ pkgconf_argv_split(const char *src, int *argc, char ***argv) } else switch(*src_iter) { + case '\"': + if (in_single_quotes) + *dst_iter++ = *src_iter; + break; + + case '\'': + in_single_quotes ^= true; + *dst_iter++ = *src_iter; + break; + case '\\': src_iter++; diff --git a/tests/lib1/fragment-quoting-2.pc b/tests/lib1/fragment-quoting-2.pc new file mode 100644 index 0000000..49c6ac7 --- /dev/null +++ b/tests/lib1/fragment-quoting-2.pc @@ -0,0 +1,10 @@ +prefix=/test +exec_prefix=${prefix} +libdir=${prefix}/lib +includedir=${prefix}/include + +Name: fragment-quoting +Description: A testing pkg-config file +Version: 1.2.3 +Cflags: -fPIC -I${includedir}/foo -DQUOTED="${prefix}/share/doc" +Cflags.private: -DFOO_STATIC diff --git a/tests/lib1/fragment-quoting-3.pc b/tests/lib1/fragment-quoting-3.pc new file mode 100644 index 0000000..4ff59fc --- /dev/null +++ b/tests/lib1/fragment-quoting-3.pc @@ -0,0 +1,10 @@ +prefix=/test +exec_prefix=${prefix} +libdir=${prefix}/lib +includedir=${prefix}/include + +Name: fragment-quoting +Description: A testing pkg-config file +Version: 1.2.3 +Cflags: -fPIC -I${includedir}/foo -DQUOTED=\"${prefix}/share/doc\" +Cflags.private: -DFOO_STATIC diff --git a/tests/parser.sh b/tests/parser.sh index 78c7813..9f1fcdb 100755 --- a/tests/parser.sh +++ b/tests/parser.sh @@ -19,7 +19,9 @@ tests_init \ flag_order_4 \ quoted \ variable_whitespace \ - fragment_quoting + fragment_quoting \ + fragment_quoting_2 \ + fragment_quoting_3 comments_body() { @@ -161,3 +163,19 @@ fragment_quoting_body() -o inline:"-fPIC -I/test/include/foo -DQUOTED='\"/test/share/doc\"' \n" \ pkgconf --cflags fragment-quoting } + +fragment_quoting_2_body() +{ + export PKG_CONFIG_PATH="${selfdir}/lib1" + atf_check \ + -o inline:"-fPIC -I/test/include/foo -DQUOTED=/test/share/doc \n" \ + pkgconf --cflags fragment-quoting-2 +} + +fragment_quoting_3_body() +{ + export PKG_CONFIG_PATH="${selfdir}/lib1" + atf_check \ + -o inline:"-fPIC -I/test/include/foo -DQUOTED=\\\"/test/share/doc\\\" \n" \ + pkgconf --cflags fragment-quoting-3 +}