system: sysupgrade: fix possibly misleading error
authorPetr Štetiar <ynezz@true.cz>
Fri, 3 Jan 2020 00:26:50 +0000 (01:26 +0100)
committerPetr Štetiar <ynezz@true.cz>
Sun, 5 Jan 2020 10:47:03 +0000 (11:47 +0100)
Fix possibly misleading error "Firmware image is broken and cannot be
installed" which could be produced by JSON without expected validation
variables, where "Validation script provided invalid input" error message
makes more sense.

Cc: Rafał Miłecki <rafal@milecki.pl>
Tested-by: Kuan-Yi Li <kyli@abysm.org>
Signed-off-by: Petr Štetiar <ynezz@true.cz>
system.c

index ffd8f7175594338c5274f11d8c789446fe770bae..0736ec9234cbf8c75e14fa62c18490f5589813a8 100644 (file)
--- a/system.c
+++ b/system.c
@@ -672,6 +672,12 @@ static int sysupgrade(struct ubus_context *ctx, struct ubus_object *obj,
 
        blobmsg_parse(validation_policy, __VALIDATION_MAX, validation, blob_data(b.head), blob_len(b.head));
 
+       if (!validation[VALIDATION_VALID] || !validation[VALIDATION_FORCEABLE] ||
+           !validation[VALIDATION_ALLOW_BACKUP]) {
+               sysupgrade_error(ctx, req, "Validation script provided invalid input");
+               return UBUS_STATUS_INVALID_ARGUMENT;
+       }
+
        valid = validation[VALIDATION_VALID] && blobmsg_get_bool(validation[VALIDATION_VALID]);
        forceable = validation[VALIDATION_FORCEABLE] && blobmsg_get_bool(validation[VALIDATION_FORCEABLE]);
        allow_backup = validation[VALIDATION_ALLOW_BACKUP] && blobmsg_get_bool(validation[VALIDATION_ALLOW_BACKUP]);