From d96002942cf66e04bd332e266bf18399224ebe91 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 7 Apr 2021 09:18:56 +1000 Subject: [PATCH] AP_Filesystem: ensure all blocks are filled on upload --- .../AP_Filesystem/AP_Filesystem_Mission.cpp | 20 +++++++++++++++++++ .../AP_Filesystem/AP_Filesystem_Mission.h | 3 +++ 2 files changed, 23 insertions(+) diff --git a/libraries/AP_Filesystem/AP_Filesystem_Mission.cpp b/libraries/AP_Filesystem/AP_Filesystem_Mission.cpp index 1f3d60c3b0..3084ad9684 100644 --- a/libraries/AP_Filesystem/AP_Filesystem_Mission.cpp +++ b/libraries/AP_Filesystem/AP_Filesystem_Mission.cpp @@ -320,6 +320,17 @@ int32_t AP_Filesystem_Mission::write(int fd, const void *buf, uint32_t count) return count; } +// see if a block of memory is all zero +bool AP_Filesystem_Mission::all_zero(const uint8_t *b, uint8_t len) const +{ + while (len--) { + if (*b++ != 0) { + return false; + } + } + return true; +} + /* finish mission upload */ @@ -342,6 +353,15 @@ bool AP_Filesystem_Mission::finish_upload(const rfile &r) return false; } + // if any item is all zeros then reject, it means client didn't + // fill in the whole file + for (uint32_t i=0; i