From 2c15891937c6fb9f3b5e70ae0f0d0d906e4c03ed Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 30 Aug 2024 19:58:07 +0200 Subject: Add more tests + m fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- libhashsum_init_hasher_from_string.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) (limited to 'libhashsum_init_hasher_from_string.c') 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) -- cgit v1.2.3-70-g09d2