From c5022fd90c1bfbba908d79fa8b7ccc20e207d30d Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Mon, 21 Sep 2026 14:55:32 +1000 Subject: [PATCH] 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. --- libraries/AP_ROMFS/AP_ROMFS.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/libraries/AP_ROMFS/AP_ROMFS.cpp b/libraries/AP_ROMFS/AP_ROMFS.cpp index 3df3e24bf83..4eb0a8a885e 100644 --- a/libraries/AP_ROMFS/AP_ROMFS.cpp +++ b/libraries/AP_ROMFS/AP_ROMFS.cpp @@ -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; } /*