mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-03 22:56:33 +02:00
wkd: Fix client issue with leading or trailing spaces in user-ids.
* common/recsel.c (recsel_parse_expr): Add flag -t. * common/stringhelp.c: Remove assert.h. (strtokenize): Factor code out to do_strtokenize. (strtokenize_nt): New. (do_strtokenize): Add arg trim to support the strtokenize_nt. * common/t-stringhelp.c (test_strtokenize_nt): New test cases. * tools/wks-util.c (wks_list_key): Use strtokenize_nt and the recsel flag -t. -- This fixes a bug with user ids with leading spaces because: wks-client lists all mail addresses from the key and matches them to the requested mail address. If there are several user-ids all with the same mail address wks-client picks one of them and then extracts exactly that user id. However, here it does not match by the mail address but by the full user-id so that we can be sure that there will be only one user-id in the final key. The filter built expression unfortunately strips leading blanks but requires a verbatim match. Thus it won't find the user id again and errors out. The new -t flag and a non-trimming strtokenize solves the problem. Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
1565baa93a
commit
b4345f7521
6 changed files with 202 additions and 22 deletions
|
@ -2,7 +2,7 @@
|
|||
* Copyright (C) 1998, 1999, 2000, 2001, 2003, 2004, 2005, 2006, 2007,
|
||||
* 2008, 2009, 2010 Free Software Foundation, Inc.
|
||||
* Copyright (C) 2014 Werner Koch
|
||||
* Copyright (C) 2015 g10 Code GmbH
|
||||
* Copyright (C) 2015, 2021 g10 Code GmbH
|
||||
*
|
||||
* This file is part of GnuPG.
|
||||
*
|
||||
|
@ -29,6 +29,7 @@
|
|||
* You should have received a copies of the GNU General Public License
|
||||
* and the GNU Lesser General Public License along with this program;
|
||||
* if not, see <https://www.gnu.org/licenses/>.
|
||||
* SPDX-License-Identifier: (LGPL-3.0-or-later OR GPL-2.0-or-later)
|
||||
*/
|
||||
|
||||
#include <config.h>
|
||||
|
@ -48,7 +49,6 @@
|
|||
# endif
|
||||
# include <windows.h>
|
||||
#endif
|
||||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
|
||||
#include "util.h"
|
||||
|
@ -216,7 +216,7 @@ trim_spaces( char *str )
|
|||
}
|
||||
|
||||
|
||||
/* Same as trim_spaces but only condider, space, tab, cr and lf as space. */
|
||||
/* Same as trim_spaces but only consider, space, tab, cr and lf as space. */
|
||||
char *
|
||||
ascii_trim_spaces (char *str)
|
||||
{
|
||||
|
@ -1293,8 +1293,8 @@ strsplit (char *string, char delim, char replacement, int *count)
|
|||
* Returns: A malloced and NULL delimited array with the tokens. On
|
||||
* memory error NULL is returned and ERRNO is set.
|
||||
*/
|
||||
char **
|
||||
strtokenize (const char *string, const char *delim)
|
||||
static char **
|
||||
do_strtokenize (const char *string, const char *delim, int trim)
|
||||
{
|
||||
const char *s;
|
||||
size_t fields;
|
||||
|
@ -1333,24 +1333,51 @@ strtokenize (const char *string, const char *delim)
|
|||
for (n = 0, p = buffer; (pend = strpbrk (p, delim)); p = pend + 1)
|
||||
{
|
||||
*pend = 0;
|
||||
while (spacep (p))
|
||||
p++;
|
||||
for (px = pend - 1; px >= p && spacep (px); px--)
|
||||
*px = 0;
|
||||
if (trim)
|
||||
{
|
||||
while (spacep (p))
|
||||
p++;
|
||||
for (px = pend - 1; px >= p && spacep (px); px--)
|
||||
*px = 0;
|
||||
}
|
||||
result[n++] = p;
|
||||
}
|
||||
while (spacep (p))
|
||||
p++;
|
||||
for (px = p + strlen (p) - 1; px >= p && spacep (px); px--)
|
||||
*px = 0;
|
||||
if (trim)
|
||||
{
|
||||
while (spacep (p))
|
||||
p++;
|
||||
for (px = p + strlen (p) - 1; px >= p && spacep (px); px--)
|
||||
*px = 0;
|
||||
}
|
||||
result[n++] = p;
|
||||
result[n] = NULL;
|
||||
|
||||
assert ((char*)(result + n + 1) == buffer);
|
||||
log_assert ((char*)(result + n + 1) == buffer);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/* Tokenize STRING using the set of delimiters in DELIM. Leading
|
||||
* spaces and tabs are removed from all tokens. The caller must xfree
|
||||
* the result.
|
||||
*
|
||||
* Returns: A malloced and NULL delimited array with the tokens. On
|
||||
* memory error NULL is returned and ERRNO is set.
|
||||
*/
|
||||
char **
|
||||
strtokenize (const char *string, const char *delim)
|
||||
{
|
||||
return do_strtokenize (string, delim, 1);
|
||||
}
|
||||
|
||||
/* Same as strtokenize but does not trim leading and trailing spaces
|
||||
* from the fields. */
|
||||
char **
|
||||
strtokenize_nt (const char *string, const char *delim)
|
||||
{
|
||||
return do_strtokenize (string, delim, 0);
|
||||
}
|
||||
|
||||
|
||||
/* Split a string into space delimited fields and remove leading and
|
||||
* trailing spaces from each field. A pointer to each field is stored
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue