From: Joel Rosdahl Date: Wed, 10 Apr 2019 20:28:46 +0000 (+0200) Subject: Add asserts to do_hash_buffer to detect misuse X-Git-Tag: v3.7~28 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8cb10eddcefbf359ec9ff9a58fc4e5cc394996cf;p=thirdparty%2Fccache.git Add asserts to do_hash_buffer to detect misuse Related to issue #374. --- diff --git a/src/hash.c b/src/hash.c index ae303322a..ae89e85fe 100644 --- a/src/hash.c +++ b/src/hash.c @@ -1,5 +1,5 @@ // Copyright (C) 2002 Andrew Tridgell -// Copyright (C) 2010-2018 Joel Rosdahl +// Copyright (C) 2010-2019 Joel Rosdahl // // This program is free software; you can redistribute it and/or modify it // under the terms of the GNU General Public License as published by the Free @@ -30,6 +30,12 @@ struct hash { static void do_hash_buffer(struct hash *hash, const void *s, size_t len) { + assert(s); + + // The hash state cannot be updated after the result has been fetched via + // hash_result/hash_result_as_bytes. + assert(!hash->md.finalized); + mdfour_update(&hash->md, (const unsigned char *)s, len); if (len > 0 && hash->debug_binary) { (void) fwrite(s, 1, len, hash->debug_binary);