Browse Source

AP_Filesystem: ensure all blocks are filled on upload

zr-v5.1
Andrew Tridgell 4 years ago
parent
commit
d96002942c
  1. 20
      libraries/AP_Filesystem/AP_Filesystem_Mission.cpp
  2. 3
      libraries/AP_Filesystem/AP_Filesystem_Mission.h

20
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) @@ -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) @@ -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<nitems; i++) {
const uint8_t *b2 = b + sizeof(hdr) + i*item_size;
if (all_zero(b2, item_size)) {
return false;
}
}
auto *mission = AP::mission();
if (mission == nullptr) {
return false;

3
libraries/AP_Filesystem/AP_Filesystem_Mission.h

@ -62,4 +62,7 @@ private: @@ -62,4 +62,7 @@ private:
// finish loading items
bool finish_upload(const rfile &r);
// see if a block of memory is all zero
bool all_zero(const uint8_t *b, uint8_t size) const;
};

Loading…
Cancel
Save