Make internal error check for unrecognized digest algorithm more robust

Fixes Coverity CID 479.
This commit is contained in:
Nick Mathewson 2011-10-06 13:02:50 -04:00
parent 2412e0e402
commit 246afc1b1b
2 changed files with 9 additions and 0 deletions

5
changes/cov479 Normal file
View File

@ -0,0 +1,5 @@
o Minor bugfixes:
- Fix internal bug-checking logic that was supposed to catch
failures in digest generation so that it will fail more robustly
if we ask for a nonexistent algorithm. Found by Coverity Scan.
Bugfix on 0.2.2.1-alpha; fixes Coverity CID 479.

View File

@ -1663,6 +1663,10 @@ crypto_digest_get_digest(crypto_digest_env_t *digest,
SHA256_Final(r, &tmpenv.d.sha2);
break;
default:
log_warn(LD_BUG, "Called with unknown algorithm %d", digest->algorithm);
/* If fragile_assert is not enabled, then we should at least not
* leak anything. */
memset(r, 0xff, sizeof(r));
tor_fragile_assert();
break;
}