diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-02-15 20:53:50 -0500 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-02-15 20:53:50 -0500 |
commit | 8da6bfa5dedbbb03d12bb81974a265feb88122c1 (patch) | |
tree | 11bd748e1c2d938929c07652ef063503535c57ee /src/or/relay.c | |
parent | 4d994e7a9c8936c9e33df90b7468e7327f1794e9 (diff) | |
parent | 91c63aae8497bc9de6533daae8f927ca09f96fd2 (diff) | |
download | tor-8da6bfa5dedbbb03d12bb81974a265feb88122c1.tar.gz tor-8da6bfa5dedbbb03d12bb81974a265feb88122c1.zip |
Merge branch 'bug24914'
Diffstat (limited to 'src/or/relay.c')
-rw-r--r-- | src/or/relay.c | 16 |
1 files changed, 9 insertions, 7 deletions
diff --git a/src/or/relay.c b/src/or/relay.c index a59b82ac64..7c21839a86 100644 --- a/src/or/relay.c +++ b/src/or/relay.c @@ -151,9 +151,9 @@ relay_digest_matches(crypto_digest_t *digest, cell_t *cell) { uint32_t received_integrity, calculated_integrity; relay_header_t rh; - crypto_digest_t *backup_digest=NULL; + crypto_digest_checkpoint_t backup_digest; - backup_digest = crypto_digest_dup(digest); + crypto_digest_checkpoint(&backup_digest, digest); relay_header_unpack(&rh, cell->payload); memcpy(&received_integrity, rh.integrity, 4); @@ -167,19 +167,21 @@ relay_digest_matches(crypto_digest_t *digest, cell_t *cell) crypto_digest_add_bytes(digest, (char*) cell->payload, CELL_PAYLOAD_SIZE); crypto_digest_get_digest(digest, (char*) &calculated_integrity, 4); + int rv = 1; + if (calculated_integrity != received_integrity) { // log_fn(LOG_INFO,"Recognized=0 but bad digest. Not recognizing."); // (%d vs %d).", received_integrity, calculated_integrity); /* restore digest to its old form */ - crypto_digest_assign(digest, backup_digest); + crypto_digest_restore(digest, &backup_digest); /* restore the relay header */ memcpy(rh.integrity, &received_integrity, 4); relay_header_pack(cell->payload, &rh); - crypto_digest_free(backup_digest); - return 0; + rv = 0; } - crypto_digest_free(backup_digest); - return 1; + + memwipe(&backup_digest, 0, sizeof(backup_digest)); + return rv; } /** Apply <b>cipher</b> to CELL_PAYLOAD_SIZE bytes of <b>in</b> |