[Pkg-gnupg-commit] [gnupg2] 02/124: common, tools: Always escape newlines when escaping data.
Daniel Kahn Gillmor
dkg at fifthhorseman.net
Wed Apr 5 15:55:26 UTC 2017
This is an automated email from the git hooks/post-receive script.
dkg pushed a commit to branch experimental
in repository gnupg2.
commit e064c75b08a523f738108428fe0c417a46e66238
Author: Justus Winter <justus at g10code.com>
Date: Wed Mar 1 17:47:47 2017 +0100
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 <justus at g10code.com>
---
common/stringhelp.c | 10 +++++++++-
tools/gpgconf-comp.c | 7 +++++++
2 files changed, 16 insertions(+), 1 deletion(-)
diff --git a/common/stringhelp.c b/common/stringhelp.c
index 341dd52..bea1466 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++] = '%';
diff --git a/tools/gpgconf-comp.c b/tools/gpgconf-comp.c
index d53947e..0c939e5 100644
--- a/tools/gpgconf-comp.c
+++ b/tools/gpgconf-comp.c
@@ -1491,6 +1491,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++;
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-gnupg/gnupg2.git
More information about the Pkg-gnupg-commit
mailing list