summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2013-07-29 15:16:02 +0200
committerWerner Koch <wk@gnupg.org>2013-07-29 15:16:02 +0200
commit43320961a8751ee28dc95cdb0ae01ea8a7ff7f91 (patch)
tree3a31b5f2377bc6e955b3b03922d7c545600cfb18 /src
parent6e0a9786637d649b48aae0e611a12e12beef9b3b (diff)
downloadlibgcrypt-43320961a8751ee28dc95cdb0ae01ea8a7ff7f91.tar.gz
sexp: Allow white space anywhere in a hex format.
* src/sexp.c (hextobyte): Remove. (hextonibble): New. (vsexp_sscan): Skip whtespace between hex nibbles. -- Before that patch a string "(a #123" " 456#") was not correctly parsed because white space was only allowed between two hex digits but not in between nibbles. Signed-off-by: Werner Koch <wk@gnupg.org>
Diffstat (limited to 'src')
-rw-r--r--src/sexp.c43
1 files changed, 21 insertions, 22 deletions
diff --git a/src/sexp.c b/src/sexp.c
index 6dedf4e8..0e96f0b0 100644
--- a/src/sexp.c
+++ b/src/sexp.c
@@ -880,27 +880,17 @@ gcry_sexp_cadr ( const gcry_sexp_t list )
}
-static int
-hextobyte( const byte *s )
+static GPG_ERR_INLINE int
+hextonibble (int s)
{
- int c=0;
-
- if( *s >= '0' && *s <= '9' )
- c = 16 * (*s - '0');
- else if( *s >= 'A' && *s <= 'F' )
- c = 16 * (10 + *s - 'A');
- else if( *s >= 'a' && *s <= 'f' ) {
- c = 16 * (10 + *s - 'a');
- }
- s++;
- if( *s >= '0' && *s <= '9' )
- c += *s - '0';
- else if( *s >= 'A' && *s <= 'F' )
- c += 10 + *s - 'A';
- else if( *s >= 'a' && *s <= 'f' ) {
- c += 10 + *s - 'a';
- }
- return c;
+ if (s >= '0' && s <= '9')
+ return s - '0';
+ else if (s >= 'A' && s <= 'F')
+ return 10 + s - 'A';
+ else if (s >= 'a' && s <= 'f')
+ return 10 + s - 'a';
+ else
+ return 0;
}
@@ -1237,10 +1227,19 @@ vsexp_sscan (gcry_sexp_t *retsexp, size_t *erroff,
STORE_LEN (c.pos, datalen);
for (hexfmt++; hexfmt < p; hexfmt++)
{
+ int tmpc;
+
if (whitespacep (hexfmt))
continue;
- *c.pos++ = hextobyte ((const unsigned char*)hexfmt);
- hexfmt++;
+ tmpc = hextonibble (*(const unsigned char*)hexfmt);
+ for (hexfmt++; hexfmt < p && whitespacep (hexfmt); hexfmt++)
+ ;
+ if (hexfmt < p)
+ {
+ tmpc *= 16;
+ tmpc += hextonibble (*(const unsigned char*)hexfmt);
+ }
+ *c.pos++ = tmpc;
}
hexfmt = NULL;
}