We currently have five public API functions that take an “array of pointers” as input parameter:
secp256k1_ec_pubkey_combine(ins: array of pointers to public keys to add)secp256k1_ec_pubkey_sort(pubkeys: array of pointers to public keys to sort)secp256k1_musig_pubkey_agg(pubkeys: array of pointers to public keys to aggregate)secp256k1_musig_nonce_agg(pubnonces: array of pointers to public nonces to aggregate)secp256k1_musig_partial_sig_agg(partial_sigs: array of pointers to partial signatures to aggregate)
Out of these, only _ec_pubkey_combine verifies that the individual pointer elements in the array are non-NULL each:
https://github.com/bitcoin-core/secp256k1/blob/e7f7083b530a55c83ce9089a7244d2d9d67ac8b2/src/secp256k1.c#L774-L775
This PR adds corresponding ARG_CHECKS for the other API functions as well, in order to avoid running into potential UB due to NULL pointer dereference. It seems to me that the tiny run-time overhead is worth it doing this for consistency and to help users in case the arrays are set up incorrectly (I’m thinking e.g. of language binding writers where getting this right might be a bit more involved).
Looking into this was motivated by a review of furszy (thanks!), who pointed out that the non-NULL checks are missing in at least one API function in the silentpayments module PR as well. Happy to add some CHECK_ILLEGAL tests if there is conceptual support for this PR.