chiark / gitweb /
Import gnupg2_2.1.18-8~deb9u1.debian.tar.bz2
[gnupg2.git] / patches / 0018-gpg-Fix-searching-for-mail-addresses-in-keyrings.patch
1 From: Justus Winter <justus@g10code.com>
2 Date: Wed, 25 Jan 2017 16:33:20 +0100
3 Subject: gpg: Fix searching for mail addresses in keyrings.
4
5 * g10/keyring.c (compare_name): Fix KEYDB_SEARCH_MODE_MAIL* searches
6 in keyrings when the UID is a plain addr-spec.
7 --
8 Previously, 'gpg --list-key "<foo@example.org>"' failed if 1/ the
9 keyring format is used and 2/ the key's UID is a plain addr-spec
10 (cf. RFC2822 section 4.3), e.g. 'foo@example.org'.
11
12 GnuPG-bug-id: 2930
13 Signed-off-by: Justus Winter <justus@g10code.com>
14 (cherry picked from commit 3f4f20ee6eff052c88647b820d9ecfdbd8df0f40)
15 ---
16  g10/keyring.c | 22 ++++++++++++++++++----
17  1 file changed, 18 insertions(+), 4 deletions(-)
18
19 diff --git a/g10/keyring.c b/g10/keyring.c
20 index f1281e98e..328290ed8 100644
21 --- a/g10/keyring.c
22 +++ b/g10/keyring.c
23 @@ -928,13 +928,27 @@ compare_name (int mode, const char *name, const char *uid, size_t uidlen)
24      else if (   mode == KEYDB_SEARCH_MODE_MAIL
25               || mode == KEYDB_SEARCH_MODE_MAILSUB
26               || mode == KEYDB_SEARCH_MODE_MAILEND) {
27 +        int have_angles = 1;
28         for (i=0, s= uid; i < uidlen && *s != '<'; s++, i++)
29             ;
30 +       if (i == uidlen)
31 +         {
32 +           /* The UID is a plain addr-spec (cf. RFC2822 section 4.3).  */
33 +           have_angles = 0;
34 +           s = uid;
35 +           i = 0;
36 +         }
37         if (i < uidlen)  {
38 -           /* skip opening delim and one char and look for the closing one*/
39 -           s++; i++;
40 -           for (se=s+1, i++; i < uidlen && *se != '>'; se++, i++)
41 -               ;
42 +           if (have_angles)
43 +             {
44 +               /* skip opening delim and one char and look for the closing one*/
45 +               s++; i++;
46 +               for (se=s+1, i++; i < uidlen && *se != '>'; se++, i++)
47 +                 ;
48 +             }
49 +           else
50 +             se = s + uidlen;
51 +
52             if (i < uidlen) {
53                 i = se - s;
54                 if (mode == KEYDB_SEARCH_MODE_MAIL) {