Commit be5e4f0
committed
Merge #1779: Add ARG_CHECKs to ensure "array of pointers" elements are non-NULL
8bcda18 test: Add non-NULL checks for "pointer of array" API functions (Sebastian Falbesoner)
5a08c1b Add ARG_CHECKs to ensure "array of pointers" elements are non-NULL (Sebastian Falbesoner)
Pull request description:
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](#1765 (comment)) (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.
ACKs for top commit:
kevkevinpal:
utACK [8bcda18](8bcda18)
john-moffett:
utACK 8bcda18
real-or-random:
utACK 8bcda18
w0xlt:
ACK 8bcda18
Tree-SHA512: 24acd6606526e3acb994e3361fde15771aa6706a6f3e7a6ae70b9a9ddb81ac1eedaac2025a027b890cecf98dab20dc378b94edde6c726888c44b9d35b7581ee1File tree
5 files changed
+54
-0
lines changed- src
- modules/musig
5 files changed
+54
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
180 | 183 | | |
181 | 184 | | |
182 | 185 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
521 | 521 | | |
522 | 522 | | |
523 | 523 | | |
| 524 | + | |
| 525 | + | |
524 | 526 | | |
525 | 527 | | |
526 | 528 | | |
527 | 529 | | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
528 | 533 | | |
529 | 534 | | |
530 | 535 | | |
| |||
782 | 787 | | |
783 | 788 | | |
784 | 789 | | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
785 | 793 | | |
786 | 794 | | |
787 | 795 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
204 | 211 | | |
205 | 212 | | |
206 | 213 | | |
| |||
350 | 357 | | |
351 | 358 | | |
352 | 359 | | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
353 | 367 | | |
354 | 368 | | |
355 | 369 | | |
| |||
474 | 488 | | |
475 | 489 | | |
476 | 490 | | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
477 | 498 | | |
478 | 499 | | |
479 | 500 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
325 | 325 | | |
326 | 326 | | |
327 | 327 | | |
| 328 | + | |
| 329 | + | |
328 | 330 | | |
329 | 331 | | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
330 | 335 | | |
331 | 336 | | |
332 | 337 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6052 | 6052 | | |
6053 | 6053 | | |
6054 | 6054 | | |
| 6055 | + | |
6055 | 6056 | | |
6056 | 6057 | | |
6057 | 6058 | | |
| |||
6245 | 6246 | | |
6246 | 6247 | | |
6247 | 6248 | | |
| 6249 | + | |
| 6250 | + | |
| 6251 | + | |
| 6252 | + | |
| 6253 | + | |
| 6254 | + | |
| 6255 | + | |
| 6256 | + | |
6248 | 6257 | | |
6249 | 6258 | | |
6250 | 6259 | | |
| |||
6640 | 6649 | | |
6641 | 6650 | | |
6642 | 6651 | | |
| 6652 | + | |
6643 | 6653 | | |
6644 | 6654 | | |
6645 | 6655 | | |
| |||
6648 | 6658 | | |
6649 | 6659 | | |
6650 | 6660 | | |
| 6661 | + | |
| 6662 | + | |
| 6663 | + | |
| 6664 | + | |
| 6665 | + | |
| 6666 | + | |
| 6667 | + | |
6651 | 6668 | | |
6652 | 6669 | | |
6653 | 6670 | | |
| |||
0 commit comments