HomePhabricator

[SECP256K1] Return NULL early in context_preallocated_create if flags invalid

Description

[SECP256K1] Return NULL early in context_preallocated_create if flags invalid

Summary:

If the user passes invalid flags to _context_create, and the default
illegal callback does not abort the program (which is possible), then we
work with the result of malloc(0), which may be undefined behavior. This
violates the promise that a library function won't crash after the
illegal callback has been called.

This commit fixes this issue by returning NULL early in _context_create
in that case.

Backport of secp256k1 PR840.

Test Plan:

ninja check-secp256k1

Reviewers: #bitcoin_abc, deadalnix

Reviewed By: #bitcoin_abc, deadalnix

Differential Revision: https://reviews.bitcoinabc.org/D8202

Details

Provenance
Tim Ruffing <crypto@timruffing.de>Authored on Oct 26 2020, 13:38
FabienCommitted on Oct 31 2020, 10:12
FabienPushed on Oct 31 2020, 10:13
Reviewer
Restricted Project
Differential Revision
D8202: [SECP256K1] Return NULL early in context_preallocated_create if flags invalid
Parents
rABCc6b104465b0b: Add unit testing for the CompressScript functions
Branches
Unknown
Tags
Unknown