Skip to content
This repository was archived by the owner on Mar 11, 2026. It is now read-only.
This repository was archived by the owner on Mar 11, 2026. It is now read-only.

Array bounds check missing for zero length string in REMOVE_TRAILING_SLASHES #16

Description

@bojake

While minor, sending "" into the REMOVE_TRAILING_SLASHES macro will result in a buffer underflow read because of the while that does not have a bounds check.

REMOVE_TRAILING_SLASHES(""):

do {
size_t _len = strlen(""); // _len = 0
while (_str[_len-1] == '/') { _str[--_len] = '\0'; } // while(_str[-1] == '/') { _str[-1] = '\0'; }
} while(0);

also is true if you give it "/" or "///" or "////////////////////////////////////////", you get it.

Change the while to be

while(_len>0 && _str[_len-1] == '/')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions