AP_ROMFS: don't list a file as though it were a directory

dir_list() accepted a name matching dirname exactly, so opendir() of a
file's path succeeded, and readdir() then skipped past the end of that
file's name, taking the name from whatever followed it in memory. Over
MAVFTP, listing a path such as @ROMFS/locations.txt was enough.

Match only names with a separator after dirname.
This commit is contained in:
Peter Barker
2026-09-24 18:35:09 +10:00
committed by Peter Barker
parent 9a2da82264
commit c5022fd90c
+3 -3
View File
@@ -121,9 +121,9 @@ const char *AP_ROMFS::dir_list(const char *dirname, uint16_t &ofs)
const size_t dlen = strlen(dirname);
for ( ; ofs < ARRAY_SIZE(files); ofs++) {
if (strncmp(dirname, files[ofs].filename, dlen) == 0) {
const char last_char = files[ofs].filename[dlen];
if (dlen != 0 && last_char != '/' && last_char != 0) {
// only a partial match, skip
if (dlen != 0 && files[ofs].filename[dlen] != '/') {
// only a partial match, or the name of a file rather than
// of a directory holding it, skip
continue;
}
/*