From 20125333e7b822e8c70ac8cef986649f0654eb56 Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Fri, 6 Nov 2015 13:20:01 +0100 Subject: [PATCH] common: Fix commit f99830b. * common/userids.c (classify_user_id): Avoid underflow. Use spacep to also trim tabs. -- This is actually not fully consistent because the now used trim_trailing_spaces uses the locale dependent isspace and not spacep. Given that the use of isspace is anyway problematic we should check whether we can chnage trim_trailing_spaces. Signed-off-by: Werner Koch --- common/userids.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/common/userids.c b/common/userids.c index 25d67410e..f9a003607 100644 --- a/common/userids.c +++ b/common/userids.c @@ -89,11 +89,15 @@ classify_user_id (const char *name, KEYDB_SEARCH_DESC *desc, int openpgp_hack) /* Skip leading and trailing spaces. */ for(s = name; *s && spacep (s); s++ ) ; - if (s[strlen(s) - 1] == ' ') + if (*s && spacep (s + strlen(s) - 1)) { - s2 = xstrdup (s); - while (s2[strlen(s2) - 1] == ' ') - s2[strlen(s2) - 1] = 0; + s2 = xtrystrdup (s); + if (!s2) + { + rc = gpg_error_from_syserror (); + goto out; + } + trim_trailing_spaces (s2); s = s2; }