Skip to content

Commit 560cfd5

Browse files
authored
c-index-test: fix buffer overflow (#129922)
We should not try to overwrite the pointer of struct, also need to add 1 for end of line.
1 parent 2130285 commit 560cfd5

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

clang/tools/c-index-test/c-index-test.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3555,11 +3555,12 @@ static CXIdxClientContainer makeClientContainer(CXClientData *client_data,
35553555
clang_indexLoc_getFileLocation(loc, &file, 0, &line, &column, 0);
35563556

35573557
len = sizeof(IndexDataStringList) + strlen(name) + digitCount(line) +
3558-
digitCount(column) + 2;
3558+
digitCount(column) + 3;
35593559
node = (IndexDataStringList *)malloc(len);
35603560
assert(node);
35613561
newStr = node->data;
3562-
snprintf(newStr, len, "%s:%d:%d", name, line, column);
3562+
snprintf(newStr, len - sizeof(IndexDataStringList), "%s:%d:%d", name, line,
3563+
column);
35633564

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

0 commit comments

Comments
 (0)