Skip to content

Commit adec5a1

Browse files
committed
Add missing null check for ctx and input keys in the public API
1 parent f4edfc7 commit adec5a1

File tree

4 files changed

+7
-5
lines changed

4 files changed

+7
-5
lines changed

include/secp256k1.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ SECP256K1_API secp256k1_context* secp256k1_context_clone(
247247
*/
248248
SECP256K1_API void secp256k1_context_destroy(
249249
secp256k1_context* ctx
250-
);
250+
) SECP256K1_ARG_NONNULL(1);
251251

252252
/** Set a callback function to be called when an illegal argument is passed to
253253
* an API call. It will only trigger for violations that are mentioned

include/secp256k1_preallocated.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ SECP256K1_API secp256k1_context* secp256k1_context_preallocated_clone(
119119
*/
120120
SECP256K1_API void secp256k1_context_preallocated_destroy(
121121
secp256k1_context* ctx
122-
);
122+
) SECP256K1_ARG_NONNULL(1);
123123

124124
#ifdef __cplusplus
125125
}

src/modules/recovery/main_impl.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ int secp256k1_ecdsa_recoverable_signature_parse_compact(const secp256k1_context*
4040
int ret = 1;
4141
int overflow = 0;
4242

43-
(void)ctx;
43+
VERIFY_CHECK(ctx != NULL);
4444
ARG_CHECK(sig != NULL);
4545
ARG_CHECK(input64 != NULL);
4646
ARG_CHECK(recid >= 0 && recid <= 3);
@@ -60,7 +60,7 @@ int secp256k1_ecdsa_recoverable_signature_parse_compact(const secp256k1_context*
6060
int secp256k1_ecdsa_recoverable_signature_serialize_compact(const secp256k1_context* ctx, unsigned char *output64, int *recid, const secp256k1_ecdsa_recoverable_signature* sig) {
6161
secp256k1_scalar r, s;
6262

63-
(void)ctx;
63+
VERIFY_CHECK(ctx != NULL);
6464
ARG_CHECK(output64 != NULL);
6565
ARG_CHECK(sig != NULL);
6666
ARG_CHECK(recid != NULL);
@@ -75,7 +75,7 @@ int secp256k1_ecdsa_recoverable_signature_convert(const secp256k1_context* ctx,
7575
secp256k1_scalar r, s;
7676
int recid;
7777

78-
(void)ctx;
78+
VERIFY_CHECK(ctx != NULL);
7979
ARG_CHECK(sig != NULL);
8080
ARG_CHECK(sigin != NULL);
8181

src/secp256k1.c

+2
Original file line numberDiff line numberDiff line change
@@ -771,6 +771,7 @@ int secp256k1_ec_pubkey_combine(const secp256k1_context* ctx, secp256k1_pubkey *
771771
secp256k1_gej Qj;
772772
secp256k1_ge Q;
773773

774+
VERIFY_CHECK(ctx != NULL);
774775
ARG_CHECK(pubnonce != NULL);
775776
memset(pubnonce, 0, sizeof(*pubnonce));
776777
ARG_CHECK(n >= 1);
@@ -779,6 +780,7 @@ int secp256k1_ec_pubkey_combine(const secp256k1_context* ctx, secp256k1_pubkey *
779780
secp256k1_gej_set_infinity(&Qj);
780781

781782
for (i = 0; i < n; i++) {
783+
ARG_CHECK(pubnonces[i] != NULL);
782784
secp256k1_pubkey_load(ctx, &Q, pubnonces[i]);
783785
secp256k1_gej_add_ge(&Qj, &Qj, &Q);
784786
}

0 commit comments

Comments
 (0)