From 0b7353bb89d2fdde69e5a0eea793d25c9a44f0f1 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 4 Jan 2023 15:24:36 +1100 Subject: [PATCH] AP_Filesystem: detect inconsistent parameter count on incorrect param count invalidate it so a 2nd param ftp will get the right count --- libraries/AP_Filesystem/AP_Filesystem_Param.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/libraries/AP_Filesystem/AP_Filesystem_Param.cpp b/libraries/AP_Filesystem/AP_Filesystem_Param.cpp index c7fa3177de..d29efe8f9d 100644 --- a/libraries/AP_Filesystem/AP_Filesystem_Param.cpp +++ b/libraries/AP_Filesystem/AP_Filesystem_Param.cpp @@ -188,6 +188,11 @@ uint8_t AP_Filesystem_Param::pack_param(const struct rfile &r, struct cursor &c, ap = AP_Param::next_scalar(&c.token, &ptype, &default_val); } if (ap == nullptr || (r.count && c.idx >= r.count)) { + if (r.count == 0 && c.idx != AP_Param::count_parameters()) { + // the parameter count is incorrect, invalidate so a + // repeated param download avoids an error + AP_Param::invalidate_count(); + } return 0; } ap->copy_name_token(c.token, name, AP_MAX_NAME_SIZE, true);