diff --git a/utils/write_updater.cpp b/utils/write_updater.cpp index 48a23173fab5888bf19ec393e86f979a4240b313..3f63b7a40fe6788a327f157cdcae0bf91d7e6ea2 100644 --- a/utils/write_updater.cpp +++ b/utils/write_updater.cpp @@ -30,6 +30,27 @@ static void PrintPrompts() cout << "clear command : write_updater clear" << endl; } +static int WriteUpdatePackage(int argc, char **argv, struct UpdateMessage &boot) +{ + if (argc < BINARY_MAX_ARGS) { + cout << "Please input correct updater command!" << endl; + return -1; + } + size_t offset = 0; + for (int i = WRITE_SECOND_CMD; i < argc; i++) { + if (argv[i] != nullptr) { + int ret = snprintf_s(boot.update + offset, sizeof(boot.update) - offset, + sizeof(boot.update) - 1 - offset, "--update_package=%s\n", argv[i]); + if (ret < 0) { + cout << "WriteUpdaterMessage snprintf_s failed!" << endl; + return -1; + } + offset += static_cast(ret); + } + } + return 0; +} + int main(int argc, char **argv) { if (argc == 1) { @@ -40,17 +61,9 @@ int main(int argc, char **argv) const std::string miscFile = "/dev/block/by-name/misc"; struct UpdateMessage boot {}; if (strcmp(argv[1], "updater") == 0) { - if (argc < BINARY_MAX_ARGS) { - cout << "Please input correct updater command!" << endl; + if (WriteUpdatePackage(argc, argv, boot) != 0) { return -1; } - if (argv[WRITE_SECOND_CMD] != nullptr) { - if (snprintf_s(boot.update, sizeof(boot.update), sizeof(boot.update) - 1, "--update_package=%s", - argv[WRITE_SECOND_CMD]) == -1) { - cout << "WriteUpdaterMessage snprintf_s failed!" << endl; - return -1; - } - } } else if (strcmp(argv[1], "user_factory_reset") == 0) { if (strncpy_s(boot.update, sizeof(boot.update), "--user_wipe_data", sizeof(boot.update) - 1) != 0) { cout << "strncpy_s failed!" << endl;