1
0
mirror of https://review.coreboot.org/flashrom.git synced 2025-07-01 22:21:16 +02:00

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 <zlatistiv@gmail.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/88162
Reviewed-by: Anastasia Klimchuk <aklm@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Nikola Z. Ivanov
2025-06-22 16:27:59 +03:00
committed by Anastasia Klimchuk
parent bc8f7c71b8
commit f1f0dd6ab3

View File

@ -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 <start>,<end>\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;
}