Skip to content

Commit 7642532

Browse files
committed
Unpoison secp outputs for MSan
The EllSwift and BIP324 ECDH helpers in key.cpp return buffers filled by libsecp256k1, which is built without sanitizer instrumentation. Mark those outputs initialized under MemorySanitizer so downstream handshake code no longer sees spurious uninitialized-value reports. Assisted-by: GitHub Copilot Assisted-by: OpenAI GPT-5-Codex
1 parent 4527acd commit 7642532

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/key.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
#include <hash.h>
1111
#include <random.h>
1212

13+
#ifdef MEMORY_SANITIZER
14+
#include <sanitizer/msan_interface.h>
15+
#endif
16+
1317
#include <secp256k1.h>
1418
#include <secp256k1_ellswift.h>
1519
#include <secp256k1_extrakeys.h>
@@ -321,6 +325,9 @@ EllSwiftPubKey CKey::EllSwiftCreate(std::span<const std::byte> ent32) const
321325

322326
// Should always succeed for valid keys (asserted above).
323327
assert(success);
328+
#ifdef MEMORY_SANITIZER
329+
__msan_unpoison(encoded_pubkey.data(), encoded_pubkey.size());
330+
#endif
324331
return {encoded_pubkey};
325332
}
326333

@@ -341,6 +348,9 @@ ECDHSecret CKey::ComputeBIP324ECDHSecret(const EllSwiftPubKey& their_ellswift, c
341348
nullptr);
342349
// Should always succeed for valid keys (assert above).
343350
assert(success);
351+
#ifdef MEMORY_SANITIZER
352+
__msan_unpoison(output.data(), output.size());
353+
#endif
344354
return output;
345355
}
346356

0 commit comments

Comments
 (0)