Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
bojake opened this issue Sep 11, 2024 · 0 comments

Comments

@bojake
Copy link

bojake commented Sep 11, 2024

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] == '/')

bojake added a commit to bojake/DCP that referenced this issue Sep 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant