AP_ROMFS: don't read past a shorter name when skipping duplicate directories

dir_list() compares an entry's leading directory with the previous
entry's using memcmp() over the directory's length, which reads past the
end of the previous name when that is shorter. strncmp() stops at its
end.
This commit is contained in:
Peter Barker
2026-09-24 18:35:09 +10:00
committed by Peter Barker
parent 7296d28042
commit 818be63b54
+2 -1
View File
@@ -133,7 +133,8 @@ const char *AP_ROMFS::dir_list(const char *dirname, uint16_t &ofs)
const char *slash = strchr(start_name, '/');
if (ofs > 0 && slash != nullptr) {
auto len = slash - start_name;
if (memcmp(files[ofs].filename, files[ofs-1].filename, len+dlen+1) == 0) {
// strncmp, not memcmp: the previous name may be shorter
if (strncmp(files[ofs].filename, files[ofs-1].filename, len+dlen+1) == 0) {
continue;
}
}