[clang] c-index-test: fix buffer overflow (PR #129922)

Matt Arsenault via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 5 17:30:46 PST 2025


================
@@ -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,
----------------
arsenm wrote:

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

https://github.com/llvm/llvm-project/pull/129922


More information about the cfe-commits mailing list