Skip to content

Commit

Permalink
REMOVE ME: Attempt to debug MSAN
Browse files Browse the repository at this point in the history
  • Loading branch information
tcharding committed Mar 13, 2024
1 parent fb676dc commit 732ee7c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
20 changes: 19 additions & 1 deletion secp256k1-sys/depend/secp256k1/src/secp256k1.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,13 +223,31 @@ static void rustsecp256k1_v0_9_2_pubkey_save(rustsecp256k1_v0_9_2_pubkey* pubkey
}
}

int rustsecp256k1_v0_9_2_ec_pubkey_parse(const rustsecp256k1_v0_9_2_context* ctx, rustsecp256k1_v0_9_2_pubkey* pubkey, const unsigned char *input, size_t inputlen) {
int rustsecp256k1_v0_9_2_ec_pubkey_parse(const rustsecp256k1_v0_9_2_context* ctx, rustsecp256k1_v0_9_2_pubkey* _pubkey, const unsigned char *input, size_t inputlen) {
rustsecp256k1_v0_9_2_ge Q;

VERIFY_CHECK(ctx != NULL);

rustsecp256k1_v0_9_2_pubkey pk;
rustsecp256k1_v0_9_2_pubkey *pubkey = &pk;

if (pubkey == NULL) {
return 1;
}

ARG_CHECK(pubkey != NULL);
memset(pubkey, 0, sizeof(*pubkey));
ARG_CHECK(input != NULL);

if (input == NULL) {
return 20;
}

if (input[0] == 4) {
return 0;
}

/* Array access is causing MSAN error but lines above are ok */
if (!rustsecp256k1_v0_9_2_eckey_pubkey_parse(&Q, input, inputlen)) {
return 0;
}
Expand Down
11 changes: 10 additions & 1 deletion src/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -470,8 +470,17 @@ impl PublicKey {
}

unsafe {
// Sanity, just ensure we can access the first element here.
if data[0] == 0xff {
panic!("first element of data is 0xff")
}
let pointer = data.as_c_ptr();
if pointer.is_null() {
panic!("pointer is null");
}

let mut pk = ffi::PublicKey::new();
if ffi::secp256k1_ec_pubkey_parse(
if ffi::secp256k1_ec_pubkey_parse( // MSAN bug here.
ffi::secp256k1_context_no_precomp,
&mut pk,
data.as_c_ptr(),
Expand Down

0 comments on commit 732ee7c

Please sign in to comment.