Skip to content

Potential UB in secp256k1_der_parse_integer? #876

@practicalswift

Description

@practicalswift

Do we consider memcpy(ra + 32 - rlen, *sig, rlen) in secp256k1_der_parse_integer to be defined in the case of rlen == 0?

secp256k1/src/ecdsa_impl.h

Lines 102 to 104 in 98dac87

static int secp256k1_der_parse_integer(secp256k1_scalar *r, const unsigned char **sig, const unsigned char *sigend) {
int overflow = 0;
unsigned char ra[32] = {0};

memcpy(ra + 32 - rlen, *sig, rlen);

Nothing high priority of course, but perhaps worth fixing? :)

This code was introduced as part of PR #334 ("Overhaul ECDSA signature parsing: strict DER, compact sigs, tests, lower-S") in 3bb9c44 back in 2015.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions