makefsdata: fix buffer corruption with very long paths

See bug #64941
This commit is contained in:
Simon Goldschmidt 2023-11-29 22:03:46 +01:00
parent ee1523630a
commit b413b04093

View File

@ -895,6 +895,10 @@ static int is_ssi_file(const char *filename)
/* build up the relative path to this file */
size_t sublen = strlen(curSubdir);
size_t freelen = sizeof(curSubdir) - sublen - 1;
if (sublen + strlen(filename) + 1 >= sizeof(curSubdir)) {
/* prevent buffer overflow */
return 0;
}
strncat(curSubdir, "/", freelen);
strncat(curSubdir, filename, freelen - 1);
curSubdir[sizeof(curSubdir) - 1] = 0;