musig_pubnonce_parse and musig_aggnonce_parse return 0 on invalid input but leave the output object untouched. Every other parse function in the library (ec_pubkey_parse, xonly_pubkey_parse, the ECDSA signature parsers, silentpayments_recipient_label_parse and musig_partial_sig_parse) clears its output first, so a failed parse leaves an object that is rejected when used.
Without that, if the object already holds a nonce (e.g. a coordinator parsing incoming nonces into a reused array, as the test vectors do), the old nonce survives a failed parse and is accepted by nonce_agg / nonce_process without any error. If the object was never initialized, a later load reads uninitialized memory.
Commits:
- clear the output right after the
nonce != NULLcheck, asec_pubkey_parsedoes, so it is also cleared whenin66is NULL - test that a failed parse (and a NULL
in66) leaves a zeroed object that serialize andnonce_agg/nonce_processreject. An all-zero aggnonce is valid (infinity), so that test uses a bad prefix byte. These checks fail without the first commit. partial_sig_parsecleared only after both ARG_CHECKs, so move its memset up the same way- document "If not, it's set to an invalid value" for the three musig parsers, matching
xonly_pubkey_parse
This is narrower than #1850: it doesn't propose a general clear-on-failure rule, it only makes the musig parsers behave like the other parsers.