1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-09-20 14:51:42 +02:00

gpg: Fix trusted introducer for user-ids with only the mbox.

* g10/trustdb.c (check_regexp): Kludge to match user-ids with only an
mbox.
--
(Also re-indented the function)
GnuPG-bug-id: 6238
This commit is contained in:
Werner Koch 2022-10-28 11:17:39 +02:00
parent bd825ead36
commit a9044b4a23
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B

View File

@ -1669,38 +1669,50 @@ sanitize_regexp(const char *old)
return new; return new;
} }
/* Used by validate_one_keyblock to confirm a regexp within a trust /* Used by validate_one_keyblock to confirm a regexp within a trust
signature. Returns 1 for match, and 0 for no match or regex * signature. Returns 1 for match, and 0 for no match or regex
error. */ * error. */
static int static int
check_regexp(const char *expr,const char *string) check_regexp (const char *expr,const char *string)
{ {
int ret; int ret;
char *regexp; char *regexp;
char *stringbuf = NULL;
regexp=sanitize_regexp(expr);
{
regex_t pat; regex_t pat;
ret=regcomp(&pat,regexp,REG_ICASE|REG_EXTENDED); regexp = sanitize_regexp (expr);
if(ret==0)
ret = regcomp (&pat, regexp, (REG_ICASE|REG_EXTENDED));
if (!ret)
{ {
ret=regexec(&pat,string,0,NULL,0); if (*regexp == '<' && !strchr (string, '<')
regfree(&pat); && is_valid_mailbox (string))
{
/* The R.E. starts with an angle bracket but STRING seems to
* be a plain mailbox (e.g. "foo@example.org"). The
* commonly used R.E. pattern "<[^>]+[@.]example\.org>$"
* won't be able to detect this. Thus we enclose STRING
* into angle brackets for checking. */
stringbuf = xstrconcat ("<", string, ">", NULL);
string = stringbuf;
} }
ret=(ret==0); ret = regexec (&pat, string, 0, NULL, 0);
regfree (&pat);
} }
if(DBG_TRUST) ret = !ret;
log_debug("regexp '%s' ('%s') on '%s': %s\n",
regexp,expr,string,ret?"YES":"NO");
xfree(regexp); if (DBG_TRUST)
log_debug ("regexp '%s' ('%s') on '%s'%s: %s\n",
regexp, expr, string, stringbuf? " (fixed)":"", ret? "YES":"NO");
xfree (regexp);
xfree (stringbuf);
return ret; return ret;
} }
/* /*
* Return true if the key is signed by one of the keys in the given * Return true if the key is signed by one of the keys in the given
* key ID list. User IDs with a valid signature are marked by node * key ID list. User IDs with a valid signature are marked by node