tools/mkimage: reject empty custom magic

Reject custom magic values when strtoull() does not parse any
digits, in addition to values outside the 32-bit uImage magic range.

Signed-off-by: Massimo Mazzariol <mazzariol.massimo@gmail.com>
Link: https://github.com/openwrt/openwrt/pull/25288
Signed-off-by: Robert Marko <robimarko@gmail.com>
This commit is contained in:
Massimo Mazzariol authored and Robert Marko committed 2026-09-25 10:05:04 +02:00
1 parent 36efe835fd
commit 6f684052de
1 file changed
+2 -2
@@ -42,7 +42,7 @@ This patch makes it possible to set a custom image magic.
break;
+ case 'M':
+ magic = strtoull(optarg, &ptr, 16);
+ if (*ptr || magic > UINT32_MAX) {
+ if (ptr == optarg || *ptr || magic > UINT32_MAX) {
+ fprintf(stderr, "%s: invalid magic %s\n",
+ params.cmdname, optarg);
+ exit(EXIT_FAILURE);
@@ -126,7 +126,7 @@ This patch makes it possible to set a custom image magic.
break;
+ case 'M':
+ magic = strtoull(optarg, &ptr, 16);
+ if (*ptr || magic > UINT32_MAX) {
+ if (ptr == optarg || *ptr || magic > UINT32_MAX) {
+ fprintf(stderr, "%s: invalid magic %s\n",
+ params.cmdname, optarg);
+ exit(EXIT_FAILURE);