diff --git a/uri.c b/uri.c index 31bbc7b6..a0e3838a 100644 --- a/uri.c +++ b/uri.c @@ -2,7 +2,6 @@ #include #include -#include #include #include #include @@ -12,8 +11,12 @@ #include "log.h" #include "xmalloc.h" +enum { + HEX_DIGIT_INVALID = 16 +}; + static uint8_t -nibble2hex(char c) +hex2nibble(char c) { switch (c) { case '0': case '1': case '2': case '3': case '4': @@ -27,8 +30,7 @@ nibble2hex(char c) return c - 'A' + 10; } - assert(false); - return 0; + return HEX_DIGIT_INVALID; } bool @@ -199,8 +201,8 @@ uri_parse(const char *uri, size_t len, encoded_len -= prefix_len; decoded_len += prefix_len; - if (isxdigit(next[1]) && isxdigit(next[2])) { - *p++ = nibble2hex(next[1]) << 4 | nibble2hex(next[2]); + if (hex2nibble(next[1]) <= 15 && hex2nibble(next[2]) <= 15) { + *p++ = hex2nibble(next[1]) << 4 | hex2nibble(next[2]); decoded_len++; encoded_len -= 3; encoded = next + 3;