mirror of
https://github.com/apache/nuttx-apps.git
synced 2026-08-01 20:29:00 +00:00
system: fastboot: bound filedump path parsing
Parse the filedump path token into the existing PATH_MAX-sized buffer before reading the optional offset and size arguments. This bounds the write without constructing a scanf format string at runtime. Signed-off-by: Old-Ding <35417409+Old-Ding@users.noreply.github.com>
This commit is contained in:
parent
eceb30e59c
commit
62d04ed484
1 changed files with 21 additions and 4 deletions
|
|
@ -871,6 +871,7 @@ static void fastboot_filedump(FAR struct fastboot_ctx_s *ctx,
|
||||||
FAR const char *arg)
|
FAR const char *arg)
|
||||||
{
|
{
|
||||||
struct stat sb;
|
struct stat sb;
|
||||||
|
size_t len;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (!arg)
|
if (!arg)
|
||||||
|
|
@ -879,14 +880,30 @@ static void fastboot_filedump(FAR struct fastboot_ctx_s *ctx,
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = sscanf(arg, "%s %" PRIdOFF " %zu", ctx->upload_param.u.file.path,
|
arg += strspn(arg, " \t\r\n");
|
||||||
&ctx->upload_param.u.file.offset, &ctx->upload_param.size);
|
len = strcspn(arg, " \t\r\n");
|
||||||
if (ret != 1 && ret != 3)
|
if (len == 0)
|
||||||
{
|
{
|
||||||
fastboot_fail(ctx, "Failed to parse arguments");
|
fastboot_fail(ctx, "Failed to parse arguments");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if (ret == 1)
|
|
||||||
|
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 != EOF && ret != 0 && ret != 2)
|
||||||
|
{
|
||||||
|
fastboot_fail(ctx, "Failed to parse arguments");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (ret != 2)
|
||||||
{
|
{
|
||||||
ret = stat(ctx->upload_param.u.file.path, &sb);
|
ret = stat(ctx->upload_param.u.file.path, &sb);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue