From 6bff510dbedadb6bf1da6d0fbab25ba0ab27ef8d Mon Sep 17 00:00:00 2001 From: Dimitris Mantzouranis Date: Wed, 31 May 2023 12:10:30 +0300 Subject: [PATCH] sonixflasher: guard the offset value --- sonixflasher.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/sonixflasher.c b/sonixflasher.c index d599d3c..ace3999 100644 --- a/sonixflasher.c +++ b/sonixflasher.c @@ -5,6 +5,7 @@ #include #include #include +#include #include @@ -155,7 +156,7 @@ bool flash(hid_device *dev, long offset, FILE *firmware, long fw_size, bool skip clear_buffer(buf, 65); write_buffer_32(buf, CMD_PREPARE); write_buffer_32(buf+5, (uint32_t)offset); - write_buffer_32(buf+9, (uint32_t)(fw_size/64)); + write_buffer_32(buf+9, (uint32_t)(fw_size/64)); hid_set_feature(dev, buf, 65); clear_buffer(buf, 65); @@ -295,7 +296,12 @@ int main(int argc, char* argv[]) file_name = optarg; break; case 'o': // offset - offset = strtol(optarg,NULL, 0); + char *endptr; + offset = strtol(optarg, &endptr, 0); + if (errno == ERANGE || *endptr != '\0') { + fprintf(stderr, "ERROR: invalid offset value '-%c'.\n", optopt); + exit(1); + } break; case 'j': // Jumploader flash_jumploader = true;