Skip to content

Commit

Permalink
sonixflasher: guard the offset value
Browse files Browse the repository at this point in the history
  • Loading branch information
dexter93 committed May 31, 2023
1 parent 49ef943 commit 6bff510
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions sonixflasher.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>

#include <hidapi.h>

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 6bff510

Please sign in to comment.