mirror of
https://github.com/ArduPilot/ardupilot.git
synced 2026-11-09 16:41:21 +08:00
AP_Filesystem: guarantee load_file() data is null-terminated
Improves safety of use and clarity of users. Termination is not included in the reported size to avoid changing user behavior or misrepresenting the file contents.
This commit is contained in:
1 parent
a5764b7413
commit
0ca37387be
5 files changed
+19
-8
No files matched your search
@@ -239,8 +239,9 @@ bool AP_Filesystem_ROMFS::set_mtime(const char *filename, const uint32_t mtime_s
|
||||
}
|
||||
|
||||
/*
|
||||
load a full file. Use delete to free the data
|
||||
we override this in ROMFS to avoid taking twice the memory
|
||||
Load a file's contents into memory. Returned object must be `delete`d to free
|
||||
the data. The data is guaranteed to be null-terminated such that it can be
|
||||
treated as a string. Overridden in ROMFS to avoid taking twice the memory.
|
||||
*/
|
||||
FileData *AP_Filesystem_ROMFS::load_file(const char *filename)
|
||||
{
|
||||
@@ -248,6 +249,7 @@ FileData *AP_Filesystem_ROMFS::load_file(const char *filename)
|
||||
if (!fd) {
|
||||
return nullptr;
|
||||
}
|
||||
// AP_ROMFS adds the guaranteed termination so we don't have to.
|
||||
fd->data = AP_ROMFS::find_decompress(filename, fd->length);
|
||||
if (fd->data == nullptr) {
|
||||
delete fd;
|
||||
|
||||
Reference in new issue
Block a user