chiark / gitweb /
common,tools: Always escape newlines when escaping data.
authorJustus Winter <justus@g10code.com>
Wed, 1 Mar 2017 16:47:47 +0000 (17:47 +0100)
committerDaniel Kahn Gillmor <dkg@fifthhorseman.net>
Mon, 18 Sep 2017 20:41:12 +0000 (21:41 +0100)
* 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 <justus@g10code.com>
(cherry picked from commit e064c75b08a523f738108428fe0c417a46e66238)

Gbp-Pq: Name 0045-common-tools-Always-escape-newlines-when-escaping-da.patch

common/stringhelp.c
tools/gpgconf-comp.c

index dea2212c457ab031f5dcfa6c1032721ae528e7ec..0abfa3d3a12aaa35734ed5f008a2e5a2c0b2f149 100644 (file)
@@ -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++] = '%';
index 530c1287f2b7b8bc837d5ee50f0a856559273f48..9358e2efac0d4fd943973517481c9d58012fbd9c 100644 (file)
@@ -1490,6 +1490,13 @@ gc_percent_escape (const char *src)
          *(dst++) = '2';
          *(dst++) = 'c';
        }
+      else if (*src == '\n')
+       {
+         /* The newline is problematic in a line-based format.  */
+         *(dst++) = '%';
+         *(dst++) = '0';
+         *(dst++) = 'a';
+       }
       else
        *(dst++) = *(src);
       src++;