From d8c465a3cd3379d4584c5cfc43a4e6c6fcd305df Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 31 Oct 2016 22:53:26 +0100 Subject: [PATCH] ifcfg-rh: fix svEscape() to properly handle double quoting '\'', '~': must not be escaped with backslash. Also, within double quotes the backslash escape character is only removed before special caracters like '$' or '`'. Not in general. Yes, it means that older versions of svEscape produced invalid escape sequences that we now treat differently. But that is not realy avoidable, it was a bug that needs to be fixed. --- src/settings/plugins/ifcfg-rh/shvar.c | 11 ++++------- .../plugins/ifcfg-rh/tests/test-ifcfg-rh.c | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index c49cda6a54..bf2077a7fb 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -174,8 +174,8 @@ _escape_ansic (const char *source) #define _char_in_strset(ch, str) (!!strchr (""str"", (ch))) -#define ESC_ESCAPEES "\"'\\$~`" /* must be escaped */ -#define ESC_SPACES " \t|&;()<>" /* only require "" */ +#define ESC_ESCAPEES "\"\\$`" /* must be escaped */ +#define ESC_SPACES " '\t~|&;()<>" /* only require "" */ const char * svEscape (const char *s, char **to_free) @@ -385,11 +385,8 @@ svUnescape (const char *value, char **to_free) /* we don't support line continuation */ goto out_error; } - if (!NM_IN_SET (value[i], '$', '`', '"', '\\')) { - /* TODO: svEscape() is not yet ready to handle properly treating - * double quotes. */ - //g_string_append_c (str, '\\'); - } + if (!NM_IN_SET (value[i], '$', '`', '"', '\\')) + g_string_append_c (str, '\\'); } g_string_append_c (str, value[i]); i++; diff --git a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c index 960f16e304..8577d2f58b 100644 --- a/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c +++ b/src/settings/plugins/ifcfg-rh/tests/test-ifcfg-rh.c @@ -8813,6 +8813,24 @@ test_svUnescape (void) V0 ("\t #a", ""), V0 ("\t #a\r", ""), V0 ("\r", ""), + V1 ("\\\"", "\""), + V1 ("\\`", "`"), + V1 ("\\$", "$"), + V1 ("\\\\", "\\"), + V1 ("\\a", "a"), + V1 ("\\b", "b"), + V1 ("\\'", "'"), + V1 ("\\~", "~"), + V1 ("\\\t", "\t"), + V1 ("\"\\\"\"", "\""), + V1 ("\"\\`\"", "`"), + V1 ("\"\\$\"", "$"), + V1 ("\"\\\\\"", "\\"), + V1 ("\"\\a\"", "\\a"), + V1 ("\"\\b\"", "\\b"), + V1 ("\"\\'\"", "\\'"), + V1 ("\"\\~\"", "\\~"), + V1 ("\"\\\t\"", "\\\t"), V0 ("ab\r", "ab"), V0 ("a'b'\r ", "ab"), V0 ("a'b' \r", "ab"),