diff options
| author | Michael Biebl <biebl@debian.org> | 2011-10-28 23:04:21 +0200 |
|---|---|---|
| committer | Michael Biebl <biebl@debian.org> | 2011-10-28 23:04:21 +0200 |
| commit | bc5840a47a748ffc2b6e7ec24c3dc5ba79664ca8 (patch) | |
| tree | bace204fa423c7489da190c08c2e86242c6b4588 /src/settings/plugins/ifcfg-rh/shvar.c | |
| parent | 0ed641587611afffa0b2cd38d5c70bdb480fa241 (diff) | |
| parent | 485d149fe80915d94ed49ea6c2c0552cf7a3e79a (diff) | |
Merge commit 'upstream/0.9.1.95'
Diffstat (limited to 'src/settings/plugins/ifcfg-rh/shvar.c')
| -rw-r--r-- | src/settings/plugins/ifcfg-rh/shvar.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/settings/plugins/ifcfg-rh/shvar.c b/src/settings/plugins/ifcfg-rh/shvar.c index db084969..0aa8efc2 100644 --- a/src/settings/plugins/ifcfg-rh/shvar.c +++ b/src/settings/plugins/ifcfg-rh/shvar.c @@ -142,10 +142,11 @@ svUnescape(char *s) { */ static const char escapees[] = "\"'\\$~`"; /* must be escaped */ static const char spaces[] = " \t|&;()<>"; /* only require "" */ +static const char newlines[] = "\n\r"; /* will be removed */ char * svEscape(const char *s) { char *new; - int i, j, mangle = 0, space = 0; + int i, j, mangle = 0, space = 0, newline = 0; int newlen, slen; static int esclen, splen; @@ -156,23 +157,26 @@ svEscape(const char *s) { for (i = 0; i < slen; i++) { if (strchr(escapees, s[i])) mangle++; if (strchr(spaces, s[i])) space++; + if (strchr(newlines, s[i])) newline++; } - if (!mangle && !space) return strdup(s); + if (!mangle && !space && !newline) return strdup(s); - newlen = slen + mangle + 3; /* 3 is extra ""\0 */ + newlen = slen + mangle - newline + 3; /* 3 is extra ""\0 */ new = g_malloc0(newlen); if (!new) return NULL; j = 0; new[j++] = '"'; for (i = 0; i < slen; i++) { + if (strchr(newlines, s[i])) + continue; if (strchr(escapees, s[i])) { new[j++] = '\\'; } new[j++] = s[i]; } new[j++] = '"'; - g_assert(j == slen + mangle + 2); /* j is the index of the '\0' */ + g_assert(j == slen + mangle - newline + 2); /* j is the index of the '\0' */ return new; } @@ -332,13 +336,13 @@ svSetValue(shvarFile *s, const char *key, const char *value, gboolean verbatim) } end: - if (newval) free(newval); - if (val1) free(val1); - if (val2) free(val2); + g_free(newval); + g_free(val1); + g_free(val2); return; bail: - if (keyValue) free (keyValue); + g_free (keyValue); goto end; } |