summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarek Kasik <mkasik@redhat.com>2013-08-08 16:20:20 +0200
committerDan Nicholson <dbn.lists@gmail.com>2013-09-15 10:27:35 -0700
commit50c2867f4a6981e085c721d936c96f174f11f415 (patch)
treed2814ea24a43638795c7137c3dd06cced7f455ac
parentf26a505826acec6b1e1af8d1efdf959913421c3a (diff)
Unquote values of requested variables
If a --variable is requested, make sure to remove the quoting since it's likely the value will be used verbatim in shell command substitution. If the quotes remain in the value, they'd get embedded in the shell variable, too. Freedesktop #67904 (https://bugs.freedesktop.org/show_bug.cgi?id=67904)
-rwxr-xr-xcheck/check-whitespace4
-rw-r--r--pkg.c20
2 files changed, 20 insertions, 4 deletions
diff --git a/check/check-whitespace b/check/check-whitespace
index e4388ba..b062bc0 100755
--- a/check/check-whitespace
+++ b/check/check-whitespace
@@ -4,6 +4,10 @@ set -e
. ${srcdir}/common
+# variables come out unquoted
+RESULT='/usr/white space/include'
+run_test --variable=includedir whitespace
+
# expect cflags from whitespace
RESULT='-Dlala=misc -I/usr/white\ space/include -I$(top_builddir) -Iinclude\ dir -Iother\ include\ dir'
run_test --cflags whitespace
diff --git a/pkg.c b/pkg.c
index 66cd515..3697fec 100644
--- a/pkg.c
+++ b/pkg.c
@@ -1042,6 +1042,7 @@ packages_get_var (GList *pkgs,
GList *tmp;
GString *str;
char *retval;
+ GError *error = NULL;
str = g_string_new ("");
@@ -1049,14 +1050,25 @@ packages_get_var (GList *pkgs,
while (tmp != NULL)
{
Package *pkg = tmp->data;
- char *var;
+ char *var, *unquoted_var;
var = package_get_var (pkg, varname);
-
if (var)
{
- g_string_append (str, var);
- g_string_append_c (str, ' ');
+ unquoted_var = g_shell_unquote (var, &error);
+ if (unquoted_var != NULL)
+ {
+ g_string_append (str, unquoted_var);
+ g_string_append_c (str, ' ');
+ g_free (unquoted_var);
+ }
+ else
+ {
+ verbose_error ("Couldn't unquote value of \"%s\": %s\n",
+ varname, error ? error->message : "unknown");
+ g_clear_error (&error);
+ }
+
g_free (var);
}