Fix possible out-of-bounds call to free()
Some checks failed
Coverity Scan / coverity (push) Has been cancelled
Bob the Builder / ${{ matrix.compiler }} (clang) (push) Has been cancelled
Bob the Builder / ${{ matrix.compiler }} (gcc) (push) Has been cancelled

The rl_filename_completion_function() may theoretically step out of
bounds and call free on random pointers.  Found by Coverity Scan.

Signed-off-by: Joachim Wiberg <troglobit@gmail.com>
This commit is contained in:
Joachim Wiberg 2025-05-24 14:40:38 +02:00
parent 127d995855
commit f735e4d1d5
No known key found for this signature in database
GPG Key ID: ECA826A37B6C7409

View File

@ -273,13 +273,21 @@ char *rl_filename_completion_function(const char *text, int state)
}
}
do {
while (i > 0)
free(av[--i]);
} while (i > 0);
if (av) {
free(av);
av = NULL;
}
if (dir) {
free(dir);
dir = NULL;
}
if (file) {
free(file);
file = NULL;
}
return NULL;
}