Skip to content

Commit 99b984b

Browse files
fix: add integer overflow check for realloc in linenoiseAddCompletion
Co-Authored-By: Jake Cosme <[email protected]>
1 parent 6b065fc commit 99b984b

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

tools/run/linenoise.cpp/linenoise.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,6 +1025,10 @@ void linenoiseAddCompletion(linenoiseCompletions *lc, const char *str) {
10251025
}
10261026

10271027
memcpy(copy.get(), str, len + 1);
1028+
1029+
if (lc->len >= SIZE_MAX / sizeof(char *) - 1) {
1030+
return;
1031+
}
10281032
char ** cvec = static_cast<char **>(std::realloc(lc->cvec, sizeof(char *) * (lc->len + 1)));
10291033
if (cvec == nullptr) {
10301034
return;

0 commit comments

Comments
 (0)