summaryrefslogtreecommitdiffstats
path: root/kbx
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2015-03-20 15:43:32 +0100
committerWerner Koch <wk@gnupg.org>2015-03-20 15:43:32 +0100
commitbebab54027d8c63574a2680c60481cfe9b88c240 (patch)
tree8bcb5c3944cd2a788b49ff08dba5e6e653db5a7f /kbx
parentcommon: Add function is_valid_mailbox_mem. (diff)
downloadgnupg2-bebab54027d8c63574a2680c60481cfe9b88c240.tar.xz
gnupg2-bebab54027d8c63574a2680c60481cfe9b88c240.zip
gpg: Consider a mailbox only userid in mail search mode.
* kbx/keybox-search.c: Include mbox-util.h. (blob_cmp_mail): Improve OpenPGP uid parsing. -- GnuPG-bug-id: 1927
Diffstat (limited to 'kbx')
-rw-r--r--kbx/keybox-search.c34
1 files changed, 24 insertions, 10 deletions
diff --git a/kbx/keybox-search.c b/kbx/keybox-search.c
index b03874d8a..1433591c1 100644
--- a/kbx/keybox-search.c
+++ b/kbx/keybox-search.c
@@ -30,6 +30,7 @@
#include "keybox-defs.h"
#include <gcrypt.h>
#include "host2net.h"
+#include "mbox-util.h"
#define xtoi_1(p) (*(p) <= '9'? (*(p)- '0'): \
*(p) <= 'F'? (*(p)-'A'+10):(*(p)-'a'+10))
@@ -435,6 +436,7 @@ blob_cmp_mail (KEYBOXBLOB blob, const char *name, size_t namelen, int substr,
for (idx=!!x509 ;idx < nuids; idx++)
{
size_t mypos = pos;
+ size_t mylen;
mypos += idx*uidinfolen;
off = get32 (buffer+mypos);
@@ -454,20 +456,32 @@ blob_cmp_mail (KEYBOXBLOB blob, const char *name, size_t namelen, int substr,
else /* OpenPGP. */
{
/* We need to forward to the mailbox part. */
+ mypos = off;
+ mylen = len;
for ( ; len && buffer[off] != '<'; len--, off++)
;
if (len < 2 || buffer[off] != '<')
- continue; /* empty name or trailing 0 not stored */
-
- off++; /* Point to first char of the mail address. */
- len--;
+ {
+ /* Mailbox not explicitly given or too short. Restore
+ OFF and LEN and check whether the entire string
+ resembles a mailbox without the angle brackets. */
+ off = mypos;
+ len = mylen;
+ if (!is_valid_mailbox_mem (buffer+off, len))
+ continue; /* Not a mail address. */
+ }
+ else /* Seems to be standard user id with mail address. */
+ {
+ off++; /* Point to first char of the mail address. */
+ len--;
+ /* Search closing '>'. */
+ for (mypos=off; len && buffer[mypos] != '>'; len--, mypos++)
+ ;
+ if (!len || buffer[mypos] != '>' || off == mypos)
+ continue; /* Not a proper mail address. */
+ len = mypos - off;
+ }
- /* Search closing '>'. */
- for (mypos=off; len && buffer[mypos] != '>'; len--, mypos++)
- ;
- if (!len || buffer[mypos] != '>' || off == mypos)
- continue; /* Not a proper mail address. */
- len = mypos - off;
}
if (substr)