-
Notifications
You must be signed in to change notification settings - Fork 14.3k
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
Conversation
@llvm/pr-subscribers-clang Author: Jinsong Ji (jsji) ChangesFull diff: https://github.com/llvm/llvm-project/pull/129922.diff 1 Files Affected:
diff --git a/clang/tools/c-index-test/c-index-test.c b/clang/tools/c-index-test/c-index-test.c
index 942500f2975e4..eb1d3de09acd0 100644
--- a/clang/tools/c-index-test/c-index-test.c
+++ b/clang/tools/c-index-test/c-index-test.c
@@ -3555,11 +3555,11 @@ 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, column);
/* Remember string so it can be freed later. */
index_data = (IndexData *)client_data;
|
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, |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will follow up. Thanks.
We should not try to overwrite the pointer of struct, also need to add 1 for end of line.
We should not try to overwrite the pointer of struct, also need to add 1 for end of line.