blobcli: fix two issues caught by klocwork
an off by one error and a bounds checking addition Change-Id: Ifad5ec4b5e358d69d35e06a7902d5593c4b7fb86 Signed-off-by: Paul Luse <paul.e.luse@intel.com> Reviewed-on: https://review.gerrithub.io/383296 Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com> Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
This commit is contained in:
parent
f71f486d0b
commit
5589fc4a6a
@ -1178,18 +1178,23 @@ line_parser(struct cli_context_t *cli_context)
|
|||||||
if (tok[0] == '$' && tok[1] == 'B') {
|
if (tok[0] == '$' && tok[1] == 'B') {
|
||||||
tok += 2;
|
tok += 2;
|
||||||
blob_num = atoi(tok);
|
blob_num = atoi(tok);
|
||||||
cli_context->argv[cli_context->argc] =
|
if (blob_num >= 0 && blob_num < MAX_SCRIPT_BLOBS) {
|
||||||
realloc(cli_context->argv[cli_context->argc], BUFSIZE);
|
cli_context->argv[cli_context->argc] =
|
||||||
if (cli_context->argv[cli_context->argc] == NULL) {
|
realloc(cli_context->argv[cli_context->argc], BUFSIZE);
|
||||||
printf("ERROR: unable to realloc memory\n");
|
if (cli_context->argv[cli_context->argc] == NULL) {
|
||||||
spdk_app_stop(-1);
|
printf("ERROR: unable to realloc memory\n");
|
||||||
|
spdk_app_stop(-1);
|
||||||
|
}
|
||||||
|
if (g_script.blobid[blob_num] == 0) {
|
||||||
|
printf("ERROR: There is no blob for $B%d\n",
|
||||||
|
blob_num);
|
||||||
|
}
|
||||||
|
snprintf(cli_context->argv[cli_context->argc], BUFSIZE,
|
||||||
|
"%" PRIu64, g_script.blobid[blob_num]);
|
||||||
|
} else {
|
||||||
|
printf("ERROR: Invalid token or exceeded max blobs of %d\n",
|
||||||
|
MAX_SCRIPT_BLOBS);
|
||||||
}
|
}
|
||||||
if (g_script.blobid[blob_num] == 0) {
|
|
||||||
printf("ERROR: There is no blob for $B%d\n",
|
|
||||||
blob_num);
|
|
||||||
}
|
|
||||||
snprintf(cli_context->argv[cli_context->argc], BUFSIZE,
|
|
||||||
"%" PRIu64, g_script.blobid[blob_num]);
|
|
||||||
}
|
}
|
||||||
cli_context->argc++;
|
cli_context->argc++;
|
||||||
tok = strtok(NULL, " ");
|
tok = strtok(NULL, " ");
|
||||||
@ -1265,7 +1270,7 @@ parse_script(struct cli_context_t *cli_context)
|
|||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (bytes_in != -1 && i < MAX_SCRIPT_LINES);
|
} while (bytes_in != -1 && i < MAX_SCRIPT_LINES - 1);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
|
|
||||||
/* add an exit cmd in case they didn't */
|
/* add an exit cmd in case they didn't */
|
||||||
|
Loading…
Reference in New Issue
Block a user