Skip to content

Commit d0a83f7

Browse files
committed
Merge #839: Prevent arithmetic on NULL pointer if the scratch space is too small
29a299e Run the undefined behaviour sanitizer on Travis (Fabien) 7506e06 Prevent arithmetic on NULL pointer if the scratch space is too small (Fabien) Pull request description: ACKs for top commit: sipa: ACK 29a299e. Reviewed the code changes and verified that building with these sanitizer flags catches the existing error, as well as a signed integer overflow if introduced. real-or-random: ACK 29a299e code inspection jonasnick: utACK 29a299e Tree-SHA512: 4d788f12f3d7b48018e884910adb9b530a05d88f504de83dadeab8a22d75da83c05a1518f7317de5f536c4dd243ea7b347b1eaddb2ca1d804c663e41b85db69d
2 parents 903b16a + 29a299e commit d0a83f7

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

.travis.yml

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ env:
3131
- BUILD=distcheck WITH_VALGRIND=no CTIMETEST=no BENCH=no
3232
- CPPFLAGS=-DDETERMINISTIC
3333
- CFLAGS=-O0 CTIMETEST=no
34+
- CFLAGS="-fsanitize=undefined -fno-omit-frame-pointer" LDFLAGS="-fsanitize=undefined -fno-omit-frame-pointer" UBSAN_OPTIONS="print_stacktrace=1:halt_on_error=1" BIGNUM=no ASM=x86_64 ECDH=yes RECOVERY=yes EXPERIMENTAL=yes SCHNORRSIG=yes CTIMETEST=no
3435
- ECMULTGENPRECISION=2
3536
- ECMULTGENPRECISION=8
3637
- RUN_VALGRIND=yes BIGNUM=no ASM=x86_64 ECDH=yes RECOVERY=yes EXPERIMENTAL=yes SCHNORRSIG=yes EXTRAFLAGS="--disable-openssl-tests" BUILD=

src/ecmult_impl.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -595,11 +595,11 @@ static int secp256k1_ecmult_strauss_batch(const secp256k1_callback* error_callba
595595
scalars = (secp256k1_scalar*)secp256k1_scratch_alloc(error_callback, scratch, n_points * sizeof(secp256k1_scalar));
596596
state.prej = (secp256k1_gej*)secp256k1_scratch_alloc(error_callback, scratch, n_points * ECMULT_TABLE_SIZE(WINDOW_A) * sizeof(secp256k1_gej));
597597
state.zr = (secp256k1_fe*)secp256k1_scratch_alloc(error_callback, scratch, n_points * ECMULT_TABLE_SIZE(WINDOW_A) * sizeof(secp256k1_fe));
598-
state.pre_a = (secp256k1_ge*)secp256k1_scratch_alloc(error_callback, scratch, n_points * 2 * ECMULT_TABLE_SIZE(WINDOW_A) * sizeof(secp256k1_ge));
599-
state.pre_a_lam = state.pre_a + n_points * ECMULT_TABLE_SIZE(WINDOW_A);
598+
state.pre_a = (secp256k1_ge*)secp256k1_scratch_alloc(error_callback, scratch, n_points * ECMULT_TABLE_SIZE(WINDOW_A) * sizeof(secp256k1_ge));
599+
state.pre_a_lam = (secp256k1_ge*)secp256k1_scratch_alloc(error_callback, scratch, n_points * ECMULT_TABLE_SIZE(WINDOW_A) * sizeof(secp256k1_ge));
600600
state.ps = (struct secp256k1_strauss_point_state*)secp256k1_scratch_alloc(error_callback, scratch, n_points * sizeof(struct secp256k1_strauss_point_state));
601601

602-
if (points == NULL || scalars == NULL || state.prej == NULL || state.zr == NULL || state.pre_a == NULL) {
602+
if (points == NULL || scalars == NULL || state.prej == NULL || state.zr == NULL || state.pre_a == NULL || state.pre_a_lam == NULL || state.ps == NULL) {
603603
secp256k1_scratch_apply_checkpoint(error_callback, scratch, scratch_checkpoint);
604604
return 0;
605605
}

0 commit comments

Comments
 (0)