[git] GnuPG - branch, master, updated. gnupg-2.2.7-165-g58baf40
by Werner Koch
cvs at cvs.gnupg.org
Mon Jul 2 20:34:54 CEST 2018
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The GNU Privacy Guard".
The branch, master has been updated
via 58baf40af641f8cbf597e508a292e85ae94688f1 (commit)
via 3978df943dc7a4781a23382be2d3b4a96a04f71f (commit)
from 1aacd12471935a354cfd85ee1805edc7eb16e6c5 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 58baf40af641f8cbf597e508a292e85ae94688f1
Author: Werner Koch <wk at gnupg.org>
Date: Mon Jul 2 20:24:10 2018 +0200
common: New function percent_data_escape.
* common/percent.c (percent_data_escape): New.
* common/t-percent.c (test_percent_data_escape): New.
Signed-off-by: Werner Koch <wk at gnupg.org>
diff --git a/common/percent.c b/common/percent.c
index 569c5fd..eeb026f 100644
--- a/common/percent.c
+++ b/common/percent.c
@@ -87,6 +87,50 @@ percent_plus_escape (const char *string)
}
+/* Create a newly alloced string from (DATA,DATALEN) with embedded
+ * Nuls quoted as %00. The standard percent unescaping can be
+ * used to reverse this encoding. */
+char *
+percent_data_escape (const void *data, size_t datalen)
+{
+ char *buffer, *p;
+ const char *s;
+ size_t n, length;
+
+ for (length=1, s=data, n=datalen; n; s++, n--)
+ {
+ if (!*s || *s == '%')
+ length += 3;
+ else
+ length++;
+ }
+
+ buffer = p = xtrymalloc (length);
+ if (!buffer)
+ return NULL;
+
+ for (s=data, n=datalen; n; s++, n--)
+ {
+ if (!*s)
+ {
+ memcpy (p, "%00", 3);
+ p += 3;
+ }
+ else if (*s == '%')
+ {
+ memcpy (p, "%25", 3);
+ p += 3;
+ }
+ else
+ *p++ = *s;
+ }
+ *p = 0;
+
+ return buffer;
+
+}
+
+
/* Do the percent and plus/space unescaping from STRING to BUFFER and
return the length of the valid buffer. Plus unescaping is only
done if WITHPLUS is true. An escaped Nul character will be
diff --git a/common/t-percent.c b/common/t-percent.c
index 145a89b..94ece92 100644
--- a/common/t-percent.c
+++ b/common/t-percent.c
@@ -99,6 +99,55 @@ test_percent_plus_escape (void)
}
+static void
+test_percent_data_escape (void)
+{
+ static struct {
+ const char *data;
+ size_t datalen;
+ const char *expect;
+ } tbl[] = {
+ {
+ "", 0,
+ ""
+ }, {
+ "a", 1,
+ "a",
+ }, {
+ "%22", 3,
+ "%2522"
+ }, {
+ "%%", 3,
+ "%25%25%00"
+ }, {
+ "\n \0BC\t", 6,
+ "\n %00BC\t"
+ }, { NULL, 0, NULL }
+ };
+ char *buf;
+ int i;
+ size_t len;
+
+ for (i=0; tbl[i].data; i++)
+ {
+ buf = percent_data_escape (tbl[i].data, tbl[i].datalen);
+ if (!buf)
+ {
+ fprintf (stderr, "out of core: %s\n", strerror (errno));
+ exit (2);
+ }
+ if (strcmp (buf, tbl[i].expect))
+ fail (i);
+ len = percent_plus_unescape_inplace (buf, 0);
+ if (len != tbl[i].datalen)
+ fail (i);
+ else if (memcmp (buf, tbl[i].data, tbl[i].datalen))
+ fail (i);
+ xfree (buf);
+ }
+}
+
+
int
main (int argc, char **argv)
@@ -109,6 +158,6 @@ main (int argc, char **argv)
/* FIXME: We escape_unescape is not tested - only
percent_plus_unescape. */
test_percent_plus_escape ();
-
+ test_percent_data_escape ();
return 0;
}
diff --git a/common/util.h b/common/util.h
index 123d880..682415d 100644
--- a/common/util.h
+++ b/common/util.h
@@ -201,6 +201,7 @@ char *hex2str_alloc (const char *hexstring, size_t *r_count);
/*-- percent.c --*/
char *percent_plus_escape (const char *string);
+char *percent_data_escape (const void *data, size_t datalen);
char *percent_plus_unescape (const char *string, int nulrepl);
char *percent_unescape (const char *string, int nulrepl);
commit 3978df943dc7a4781a23382be2d3b4a96a04f71f
Author: Werner Koch <wk at gnupg.org>
Date: Mon Jul 2 20:22:42 2018 +0200
agent: Fix segv running in --server mode
* agent/command.c (start_command_handler): Do not write to
CLIENT_CREDS after an error.
--
assuan_get_peercred is special insofar that it returns a pointer into
CTX. Writing data via this pointer should never be done.
Fixes-commit: 28aa6890588cc108639951bb4bef03ac17743046
Signed-off-by: Werner Koch <wk at gnupg.org>
diff --git a/agent/command.c b/agent/command.c
index 1a08cfc..9bc3b02 100644
--- a/agent/command.c
+++ b/agent/command.c
@@ -3351,7 +3351,8 @@ start_command_handler (ctrl_t ctrl, gnupg_fd_t listen_fd, gnupg_fd_t fd)
for (;;)
{
- assuan_peercred_t client_creds;
+ assuan_peercred_t client_creds; /* Note: Points into CTX. */
+ pid_t pid;
rc = assuan_accept (ctx);
if (gpg_err_code (rc) == GPG_ERR_EOF || rc == -1)
@@ -3367,17 +3368,21 @@ start_command_handler (ctrl_t ctrl, gnupg_fd_t listen_fd, gnupg_fd_t fd)
rc = assuan_get_peercred (ctx, &client_creds);
if (rc)
{
- log_info ("Assuan get_peercred failed: %s\n", gpg_strerror (rc));
- client_creds->pid = assuan_get_pid (ctx);
+
+ if (listen_fd == GNUPG_INVALID_FD && fd == GNUPG_INVALID_FD)
+ ;
+ else
+ log_info ("Assuan get_peercred failed: %s\n", gpg_strerror (rc));
+ pid = assuan_get_pid (ctx);
ctrl->client_uid = -1;
}
- ctrl->server_local->connect_from_self =
- (client_creds->pid == getpid ());
- if (client_creds->pid != ASSUAN_INVALID_PID)
- ctrl->client_pid = (unsigned long)client_creds->pid;
else
- ctrl->client_pid = 0;
- ctrl->client_uid = client_creds->uid;
+ {
+ pid = client_creds->pid;
+ ctrl->client_uid = client_creds->uid;
+ }
+ ctrl->client_pid = (pid == ASSUAN_INVALID_PID)? 0 : (unsigned long)pid;
+ ctrl->server_local->connect_from_self = (pid == getpid ());
rc = assuan_process (ctx);
if (rc)
-----------------------------------------------------------------------
Summary of changes:
agent/command.c | 23 ++++++++++++++---------
common/percent.c | 44 ++++++++++++++++++++++++++++++++++++++++++++
common/t-percent.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++-
common/util.h | 1 +
4 files changed, 109 insertions(+), 10 deletions(-)
hooks/post-receive
--
The GNU Privacy Guard
http://git.gnupg.org
More information about the Gnupg-commits
mailing list