Skip to content

htsAddLink walks back from an empty codebase, one byte before the buffer #730

Description

@xroche

htsAddLink() builds its codebase and then walks back to the last /:

a = codebase + strlen(codebase) - 1;
while ((*a) && (*a != '/') && (a > codebase))
  a--;

When codebase is empty, a is codebase - 1 and the loop dereferences it before a > codebase stops it. That is the same idiom #729 fixes in lienrelatif(), one byte read before a stack buffer.

codebase is strcpybuffed from heap(ptr)->fil or from heap(heap(ptr)->precedent)->fil, so whether an empty value reaches it depends on which links can carry an empty fil. I have not built a reproducer, and unlike the lienrelatif() case there is no query-stripping pre-pass handing it an empty string, so this may well be unreachable in practice. Filing it because the shape is identical and the guard is one line either way.

Found while reviewing the same idiom for #729. Untouched by that PR and by #718.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions