diff --git a/system/fastboot/fastboot.c b/system/fastboot/fastboot.c index d443bb9c879..8c7448e3e71 100644 --- a/system/fastboot/fastboot.c +++ b/system/fastboot/fastboot.c @@ -871,6 +871,7 @@ static void fastboot_filedump(FAR struct fastboot_ctx_s *ctx, FAR const char *arg) { struct stat sb; + size_t len; int ret; if (!arg) @@ -879,14 +880,30 @@ static void fastboot_filedump(FAR struct fastboot_ctx_s *ctx, return; } - ret = sscanf(arg, "%s %" PRIdOFF " %zu", ctx->upload_param.u.file.path, + arg += strspn(arg, " \t\r\n"); + len = strcspn(arg, " \t\r\n"); + if (len == 0) + { + fastboot_fail(ctx, "Failed to parse arguments"); + return; + } + + if (len >= sizeof(ctx->upload_param.u.file.path)) + { + len = sizeof(ctx->upload_param.u.file.path) - 1; + } + + memcpy(ctx->upload_param.u.file.path, arg, len); + ctx->upload_param.u.file.path[len] = '\0'; + + ret = sscanf(arg + len, "%" PRIdOFF " %zu", &ctx->upload_param.u.file.offset, &ctx->upload_param.size); - if (ret != 1 && ret != 3) + if (ret != EOF && ret != 0 && ret != 2) { fastboot_fail(ctx, "Failed to parse arguments"); return; } - else if (ret == 1) + else if (ret != 2) { ret = stat(ctx->upload_param.u.file.path, &sb); if (ret < 0)