if (smartlist_len(hash_words) != 3 ||
strcmp(smartlist_get(hash_words, 0), hash_token)) {
log_info(LD_CONSDIFF, "The provided consensus diff does not include "
- "the necessary sha256 digests.");
+ "the necessary digests.");
goto error_cleanup;
}
if (strlen(cons1_hash_hex) != HEX_DIGEST256_LEN ||
strlen(cons2_hash_hex) != HEX_DIGEST256_LEN) {
log_info(LD_CONSDIFF, "The provided consensus diff includes "
- "base16-encoded sha256 digests of incorrect size.");
+ "base16-encoded digests of incorrect size.");
goto error_cleanup;
}
base16_decode(cons2_hash, DIGEST256_LEN,
cons2_hash_hex, HEX_DIGEST256_LEN) != DIGEST256_LEN) {
log_info(LD_CONSDIFF, "The provided consensus diff includes "
- "malformed sha256 digests.");
+ "malformed digests.");
goto error_cleanup;
}
char hex_digest1[HEX_DIGEST256_LEN+1];
char e_hex_digest1[HEX_DIGEST256_LEN+1];
log_warn(LD_CONSDIFF, "Refusing to apply consensus diff because "
- "the base consensus doesn't match its own digest as found in "
+ "the base consensus doesn't match the digest as found in "
"the consensus diff header.");
base16_encode(hex_digest1, HEX_DIGEST256_LEN+1,
digests1->d[DIGEST_SHA256], DIGEST256_LEN);
/* To avoid copying memory or iterating over all the elements, make a
* read-only smartlist without the two header lines.
*/
+ /* XXXX prop140 abstraction violation; never do this. */
smartlist_t *ed_diff = tor_malloc(sizeof(smartlist_t));
ed_diff->list = diff->list+2;
ed_diff->num_used = diff->num_used-2;
if (fast_memneq(cons2_digests.d[DIGEST_SHA256], e_cons2_hash,
DIGEST256_LEN)) {
log_warn(LD_CONSDIFF, "Refusing to apply consensus diff because "
- "the resulting consensus doesn't match its own digest as found in "
+ "the resulting consensus doesn't match the digest as found in "
"the consensus diff header.");
char hex_digest2[HEX_DIGEST256_LEN+1];
char e_hex_digest2[HEX_DIGEST256_LEN+1];
(void)arg;
cons1 = smartlist_new();
diff = smartlist_new();
+ setup_capture_of_logs(LOG_INFO);
cons1_str = tor_strdup(
"header\nnetwork-status-version foo\n"
/* diff doesn't have enough lines. */
cons2 = consdiff_apply_diff(cons1, diff, &digests1);
tt_ptr_op(NULL, OP_EQ, cons2);
+ expect_single_log_msg_containing("too short")
/* first line doesn't match format-version string. */
smartlist_add(diff, (char*)"foo-bar");
smartlist_add(diff, (char*)"header-line");
+ mock_clean_saved_logs();
cons2 = consdiff_apply_diff(cons1, diff, &digests1);
tt_ptr_op(NULL, OP_EQ, cons2);
+ expect_single_log_msg_containing("format is not known")
/* The first word of the second header line is not "hash". */
smartlist_clear(diff);
smartlist_add(diff, (char*)"network-status-diff-version 1");
smartlist_add(diff, (char*)"word a b");
+ smartlist_add(diff, (char*)"x");
+ mock_clean_saved_logs();
cons2 = consdiff_apply_diff(cons1, diff, &digests1);
tt_ptr_op(NULL, OP_EQ, cons2);
+ expect_single_log_msg_containing("does not include the necessary digests")
/* Wrong number of words after "hash". */
smartlist_clear(diff);
smartlist_add(diff, (char*)"network-status-diff-version 1");
smartlist_add(diff, (char*)"hash a b c");
+ mock_clean_saved_logs();
cons2 = consdiff_apply_diff(cons1, diff, &digests1);
tt_ptr_op(NULL, OP_EQ, cons2);
+ expect_single_log_msg_containing("does not include the necessary digests")
/* base16 sha256 digests do not have the expected length. */
smartlist_clear(diff);
smartlist_add(diff, (char*)"network-status-diff-version 1");
smartlist_add(diff, (char*)"hash aaa bbb");
+ mock_clean_saved_logs();
cons2 = consdiff_apply_diff(cons1, diff, &digests1);
tt_ptr_op(NULL, OP_EQ, cons2);
+ expect_single_log_msg_containing("includes base16-encoded digests of "
+ "incorrect size")
/* base16 sha256 digests contain non-base16 characters. */
smartlist_clear(diff);
smartlist_add(diff, (char*)"hash"
" ????????????????????????????????????????????????????????????????"
" ----------------------------------------------------------------");
+ mock_clean_saved_logs();
cons2 = consdiff_apply_diff(cons1, diff, &digests1);
tt_ptr_op(NULL, OP_EQ, cons2);
+ expect_single_log_msg_containing("includes malformed digests")
/* Invalid ed diff.
* As tested in apply_ed_diff, but check that apply_diff does return NULL if
/* sha256 of cons2. */
" 635D34593020C08E5ECD865F9986E29D50028EFA62843766A8197AD228A7F6AA");
smartlist_add(diff, (char*)"foobar");
+ mock_clean_saved_logs();
cons2 = consdiff_apply_diff(cons1, diff, &digests1);
tt_ptr_op(NULL, OP_EQ, cons2);
+ expect_single_log_msg_containing("because an ed command was missing a line "
+ "number")
/* Base consensus doesn't match its digest as found in the diff. */
smartlist_clear(diff);
" 3333333333333333333333333333333333333333333333333333333333333333"
/* sha256 of cons2. */
" 635D34593020C08E5ECD865F9986E29D50028EFA62843766A8197AD228A7F6AA");
+ mock_clean_saved_logs();
cons2 = consdiff_apply_diff(cons1, diff, &digests1);
tt_ptr_op(NULL, OP_EQ, cons2);
+ expect_log_msg_containing("base consensus doesn't match the digest "
+ "as found");
/* Resulting consensus doesn't match its digest as found in the diff. */
smartlist_clear(diff);
" C2199B6827514F39ED9B3F2E2E73735C6C5468FD636240BB454C526220DE702A"
/* bogus sha256. */
" 3333333333333333333333333333333333333333333333333333333333333333");
+ mock_clean_saved_logs();
cons2 = consdiff_apply_diff(cons1, diff, &digests1);
tt_ptr_op(NULL, OP_EQ, cons2);
+ expect_log_msg_containing("resulting consensus doesn't match the "
+ "digest as found")
/* Very simple test, only to see that nothing errors. */
smartlist_clear(diff);
smartlist_clear(diff);
done:
+ teardown_capture_of_logs();
tor_free(cons1_str);
smartlist_free(cons1);
smartlist_free(diff);