Commit 5589fc4a authored by Paul Luse's avatar Paul Luse Committed by Daniel Verkamp
Browse files

blobcli: fix two issues caught by klocwork



an off by one error and a bounds checking addition

Change-Id: Ifad5ec4b5e358d69d35e06a7902d5593c4b7fb86
Signed-off-by: default avatarPaul Luse <paul.e.luse@intel.com>
Reviewed-on: https://review.gerrithub.io/383296


Reviewed-by: default avatarDaniel Verkamp <daniel.verkamp@intel.com>
Tested-by: default avatarSPDK Automated Test System <sys_sgsw@intel.com>
parent f71f486d
Loading
Loading
Loading
Loading
+17 −12
Original line number Diff line number Diff line
@@ -1178,6 +1178,7 @@ line_parser(struct cli_context_t *cli_context)
		if (tok[0] == '$' && tok[1] == 'B') {
			tok += 2;
			blob_num = atoi(tok);
			if (blob_num >= 0 && blob_num < MAX_SCRIPT_BLOBS) {
				cli_context->argv[cli_context->argc] =
					realloc(cli_context->argv[cli_context->argc], BUFSIZE);
				if (cli_context->argv[cli_context->argc] == NULL) {
@@ -1190,6 +1191,10 @@ line_parser(struct cli_context_t *cli_context)
				}
				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);
			}
		}
		cli_context->argc++;
		tok = strtok(NULL, " ");
@@ -1265,7 +1270,7 @@ parse_script(struct cli_context_t *cli_context)
				i++;
			}
		}
	} while (bytes_in != -1 && i < MAX_SCRIPT_LINES);
	} while (bytes_in != -1 && i < MAX_SCRIPT_LINES - 1);
	fclose(fp);

	/* add an exit cmd in case they didn't */