Skip to content

c-index-test: fix buffer overflow #129922

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

Merged
merged 2 commits into from
Mar 6, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions clang/tools/c-index-test/c-index-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -3555,11 +3555,12 @@ static CXIdxClientContainer makeClientContainer(CXClientData *client_data,
clang_indexLoc_getFileLocation(loc, &file, 0, &line, &column, 0);

len = sizeof(IndexDataStringList) + strlen(name) + digitCount(line) +
digitCount(column) + 2;
digitCount(column) + 3;
node = (IndexDataStringList *)malloc(len);
assert(node);
newStr = node->data;
snprintf(newStr, len, "%s:%d:%d", name, line, column);
snprintf(newStr, len - sizeof(IndexDataStringList), "%s:%d:%d", name, line,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe factor len out of the original part and add to the malloc arg

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will follow up. Thanks.

column);

/* Remember string so it can be freed later. */
index_data = (IndexData *)client_data;
Expand Down