From f1f0dd6ab3714186630a78f52f6d959598602689 Mon Sep 17 00:00:00 2001 From: "Nikola Z. Ivanov" Date: Sun, 22 Jun 2025 16:27:59 +0300 Subject: [PATCH] cli_classic.c: Reimplement parse_wp_range Current method modifies the optarg string and causes it to not get printed in future debug log. For example writing the log to a file with -o will show "Command line" without the size parameter of the range. Tested by logging the output and reading the log: ./flashrom -p linux_spi:dev=/dev/spidev0.0 -c "W25Q64JV-.Q" \ --wp-range 0x0,0x00001000 -o logfile && grep 'Command line' logfile Change-Id: I77acd49a5fa17a0af69b4fb1371a131a5249d3dc Signed-off-by: Nikola Z. Ivanov Reviewed-on: https://review.coreboot.org/c/flashrom/+/88162 Reviewed-by: Anastasia Klimchuk Tested-by: build bot (Jenkins) --- cli_classic.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/cli_classic.c b/cli_classic.c index 8b6474b06..870f8da0c 100644 --- a/cli_classic.c +++ b/cli_classic.c @@ -219,26 +219,23 @@ static bool check_file(FILE *file) static int parse_wp_range(unsigned int *start, unsigned int *len) { - char *endptr = NULL, *token = NULL; + char *delim = NULL; if (!optarg) { msg_gerr("Error: No wp-range values provided\n"); return -1; } - token = strtok(optarg, ","); - if (!token) { - msg_gerr("Error: Invalid wp-range argument format\n"); + if ((delim = strchr(optarg, ',')) != strrchr(optarg, ',') || + delim == NULL || + delim == optarg || + *(delim + 1) == '\0') { + msg_gerr("Error: Invalid wp-range argument format. Valid format is --wp-range ,\n"); return -1; } - *start = strtoul(token, &endptr, 0); - token = strtok(NULL, ","); - if (!token) { - msg_gerr("Error: Invalid wp-range argument format\n"); - return -1; - } - *len = strtoul(token, &endptr, 0); + *start = strtoul(optarg, NULL, 0); + *len = strtoul(delim+1, NULL, 0); return 0; }