diff options
Diffstat (limited to 'libhashsum_init_hasher_from_string.c')
-rw-r--r-- | libhashsum_init_hasher_from_string.c | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/libhashsum_init_hasher_from_string.c b/libhashsum_init_hasher_from_string.c index c4bf441..a1ee827 100644 --- a/libhashsum_init_hasher_from_string.c +++ b/libhashsum_init_hasher_from_string.c @@ -12,8 +12,9 @@ with_n(int (*initfunc)(struct libhashsum_hasher *, size_t), struct libhashsum_ha if (!p || *++p == ']') return initfunc(this, 0); - if (*p++ != 'n' && *p++ != 'N') + if (*p != 'n' && *p != 'N') goto einval; + p++; if (*p++ != '=' || !('1' <= *p && *p <= '9')) goto einval; @@ -62,8 +63,11 @@ with_rcnz(int (*initfunc)(struct libhashsum_hasher *, size_t, size_t, size_t, si size_t r = 0, c = 0, n = 0, z = 0; p = strchr(algorithm, '['); - if (!p || *++p == ']') + if (!p || *++p == ']') { + if (p && *p) + goto einval; return initfunc(this, 0, 0, 0, 0); + } for (;;) { if (*p == 'r' || *p == 'R') { @@ -111,16 +115,21 @@ with_salt(int (*initfunc)(struct libhashsum_hasher *, const void *), if (!p || *++p == ']') return initfunc(this, NULL); - if (*p++ != 's' && *p++ != 'S') + if (*p != 's' && *p != 'S') goto einval; - if (*p++ != 'a' && *p++ != 'A') + p++; + if (*p != 'a' && *p != 'A') goto einval; - if (*p++ != 'l' && *p++ != 'L') + p++; + if (*p != 'l' && *p != 'L') goto einval; - if (*p++ != 't' && *p++ != 'T') + p++; + if (*p != 't' && *p != 'T') goto einval; - if (*p++ != '=') + p++; + if (*p != '=') goto einval; + p++; if (p[0] == '0' && (p[1] == 'x' || p[1] == 'X')) p = &p[2]; @@ -138,9 +147,10 @@ with_salt(int (*initfunc)(struct libhashsum_hasher *, const void *), break; } - a = (uint8_t)(((*p & 15) + (*p > '9' ? 9 : 0)) << 4); - b = (uint8_t)(((*p & 15) + (*p > '9' ? 9 : 0)) << 0); + a = (uint8_t)(((p[0] & 15) + (p[0] > '9' ? 9 : 0)) << 4); + b = (uint8_t)(((p[1] & 15) + (p[1] > '9' ? 9 : 0)) << 0); salt[salti++] = (uint8_t)(a | b); + p = &p[2]; } if (*p++ != ']' || *p) |