diff options
author | Mattias Andrée <maandree@kth.se> | 2024-08-30 19:58:07 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2024-08-30 19:58:07 +0200 |
commit | 2c15891937c6fb9f3b5e70ae0f0d0d906e4c03ed (patch) | |
tree | d3d3cc3784207210fc7c63cca267257b20153b67 /libhashsum_init_hasher_from_string.c | |
parent | m + add man pages (diff) | |
download | libhashsum-2c15891937c6fb9f3b5e70ae0f0d0d906e4c03ed.tar.gz libhashsum-2c15891937c6fb9f3b5e70ae0f0d0d906e4c03ed.tar.bz2 libhashsum-2c15891937c6fb9f3b5e70ae0f0d0d906e4c03ed.tar.xz |
Add more tests + m fixes
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-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) |