diff options
author | Mattias Andrée <maandree@kth.se> | 2021-07-27 16:01:30 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2021-07-27 16:07:05 +0200 |
commit | 411e0a694f3ed02e1d98abe923601d511bc15b59 (patch) | |
tree | 887856fdaf376eec294c8ef4492c26e66fe977c7 /libkeccak_generalised_sum_fd.c | |
parent | Improve makefile (diff) | |
download | libkeccak-411e0a694f3ed02e1d98abe923601d511bc15b59.tar.gz libkeccak-411e0a694f3ed02e1d98abe923601d511bc15b59.tar.bz2 libkeccak-411e0a694f3ed02e1d98abe923601d511bc15b59.tar.xz |
Add ALLOCA_LIMIT to fix bug #13 on GitHub reported by Justin Gottula
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | libkeccak_generalised_sum_fd.c | 20 |
1 files changed, 17 insertions, 3 deletions
diff --git a/libkeccak_generalised_sum_fd.c b/libkeccak_generalised_sum_fd.c index 879371b..4aa7a94 100644 --- a/libkeccak_generalised_sum_fd.c +++ b/libkeccak_generalised_sum_fd.c @@ -33,8 +33,16 @@ libkeccak_generalised_sum_fd(int fd, struct libkeccak_state *restrict state, con if (attr.st_blksize > 0) blksize = (size_t)attr.st_blksize; #endif - + +#if ALLOCA_LIMIT > 0 + if (blksize > (size_t)ALLOCA_LIMIT) + blksize = (size_t)ALLOCA_LIMIT; chunk = alloca(blksize); +#else + chunk = malloc(blksize); + if (!chunk) + return -1; +#endif for (;;) { got = read(fd, chunk, blksize); @@ -43,11 +51,17 @@ libkeccak_generalised_sum_fd(int fd, struct libkeccak_state *restrict state, con break; if (errno == EINTR) continue; - return -1; + goto fail; } if (libkeccak_fast_update(state, chunk, (size_t)got) < 0) - return -1; + goto fail; } return libkeccak_fast_digest(state, NULL, 0, 0, suffix, hashsum); + +fail: +#if ALLOCA_LIMIT <= 0 + free(chunk); +#endif + return -1; } |