mirror of
https://github.com/ArduPilot/ardupilot.git
synced 2026-10-02 10:23:25 +08:00
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:
committed by
Peter Barker
parent
7296d28042
commit
818be63b54
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user