aboutsummaryrefslogtreecommitdiffstats
path: root/common/stringhelp.c
diff options
context:
space:
mode:
authorJustus Winter <[email protected]>2017-03-01 16:47:47 +0000
committerJustus Winter <[email protected]>2017-03-02 08:31:11 +0000
commite064c75b08a523f738108428fe0c417a46e66238 (patch)
tree114eadbf50dcfbdd6b86c7c50cf255c585348fec /common/stringhelp.c
parentPost release updates. (diff)
downloadgnupg-e064c75b08a523f738108428fe0c417a46e66238.tar.gz
gnupg-e064c75b08a523f738108428fe0c417a46e66238.zip
common,tools: Always escape newlines when escaping data.
* common/stringhelp.c (do_percent_escape): Always escape newlines. * tools/gpgconf-comp.c (gc_percent_escape): Likewise. -- Newlines always pose a problem for a line-based communication format. GnuPG-bug-id: 2387 Signed-off-by: Justus Winter <[email protected]>
Diffstat (limited to 'common/stringhelp.c')
-rw-r--r--common/stringhelp.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/common/stringhelp.c b/common/stringhelp.c
index 341dd525b..bea146647 100644
--- a/common/stringhelp.c
+++ b/common/stringhelp.c
@@ -1052,7 +1052,8 @@ do_percent_escape (const char *str, const char *extra, int die)
return NULL;
for (i=j=0; str[i]; i++)
- if (str[i] == ':' || str[i] == '%' || (extra && strchr (extra, str[i])))
+ if (str[i] == ':' || str[i] == '%' || str[i] == '\n'
+ || (extra && strchr (extra, str[i])))
j++;
if (die)
ptr = xmalloc (i + 2 * j + 1);
@@ -1077,6 +1078,13 @@ do_percent_escape (const char *str, const char *extra, int die)
ptr[i++] = '2';
ptr[i++] = '5';
}
+ else if (*str == '\n')
+ {
+ /* The newline is problematic in a line-based format. */
+ ptr[i++] = '%';
+ ptr[i++] = '0';
+ ptr[i++] = 'a';
+ }
else if (extra && strchr (extra, *str))
{
ptr[i++] = '%';