Page MenuHomePhabricator

[SECP256K1] Return NULL early in context_preallocated_create if flags invalid
ClosedPublic

Authored by Fabien on Oct 30 2020, 19:35.

Details

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

Diff Detail

Repository
rABC Bitcoin ABC
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Fabien requested review of this revision.Oct 30 2020, 19:36
Fabien retitled this revision from Return NULL early in context_preallocated_create if flags invalid to [SECP256K1] Return NULL early in context_preallocated_create if flags invalid.Oct 30 2020, 21:09
This revision is now accepted and ready to land.Oct 30 2020, 22:29