diff options
author | Werner Koch <wk@gnupg.org> | 2013-07-29 15:16:02 +0200 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2013-07-29 15:16:02 +0200 |
commit | 43320961a8751ee28dc95cdb0ae01ea8a7ff7f91 (patch) | |
tree | 3a31b5f2377bc6e955b3b03922d7c545600cfb18 /src/sexp.c | |
parent | 6e0a9786637d649b48aae0e611a12e12beef9b3b (diff) | |
download | libgcrypt-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/sexp.c')
-rw-r--r-- | src/sexp.c | 43 |
1 files changed, 21 insertions, 22 deletions
@@ -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; } |