Skip to content

Commit

Permalink
Merge bitcoin#774: tests: Abort if malloc() fails during context clon…
Browse files Browse the repository at this point in the history
…ing tests

2e1b9e0 tests: Abort if malloc() fails during context cloning tests (Tim Ruffing)

Pull request description:

  Found by the clang static analyzer.

  This is the worst true positive that it found. I feel somewhat proud.

ACKs for top commit:
  elichai:
    tACK 2e1b9e0

Tree-SHA512: bf9a3b6c2b8beaafd230ece00a9a69dd884a35b6d2243502ebfded3f77a454e80ef922791bd48c17aa4814a275550957071c045912080a616dd5ed704a70aab7
  • Loading branch information
real-or-random committed Jul 28, 2020
2 parents 3e5cfc5 + 2e1b9e0 commit 40412b1
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/tests.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,10 @@ void run_context_tests(int use_prealloc) {
ecount2 = 10;
secp256k1_context_set_illegal_callback(vrfy, counting_illegal_callback_fn, &ecount);
secp256k1_context_set_illegal_callback(sign, counting_illegal_callback_fn, &ecount2);
secp256k1_context_set_error_callback(sign, counting_illegal_callback_fn, NULL);
CHECK(vrfy->error_callback.fn != sign->error_callback.fn);
/* set error callback (to a function that still aborts in case malloc() fails in secp256k1_context_clone() below) */
secp256k1_context_set_error_callback(sign, secp256k1_default_illegal_callback_fn, NULL);
CHECK(sign->error_callback.fn != vrfy->error_callback.fn);
CHECK(sign->error_callback.fn == secp256k1_default_illegal_callback_fn);

/* check if sizes for cloning are consistent */
CHECK(secp256k1_context_preallocated_clone_size(none) == secp256k1_context_preallocated_size(SECP256K1_CONTEXT_NONE));
Expand Down Expand Up @@ -239,7 +241,8 @@ void run_context_tests(int use_prealloc) {
}

/* Verify that the error callback makes it across the clone. */
CHECK(vrfy->error_callback.fn != sign->error_callback.fn);
CHECK(sign->error_callback.fn != vrfy->error_callback.fn);
CHECK(sign->error_callback.fn == secp256k1_default_illegal_callback_fn);
/* And that it resets back to default. */
secp256k1_context_set_error_callback(sign, NULL, NULL);
CHECK(vrfy->error_callback.fn == sign->error_callback.fn);
Expand Down

0 comments on commit 40412b1

Please sign in to comment.