|
|
c9eda1 |
From b857ce058d6f7fa3fa47c839bc86de243cd1fd4e Mon Sep 17 00:00:00 2001
|
|
|
c9eda1 |
From: Peter Jones <pjones@redhat.com>
|
|
|
c9eda1 |
Date: Mon, 20 Oct 2014 12:15:26 -0400
|
|
|
c9eda1 |
Subject: [PATCH 2/2] Make all the other places we're parsing XXXX also do a
|
|
|
c9eda1 |
better job.
|
|
|
c9eda1 |
|
|
|
c9eda1 |
This is related to https://github.com/vathpela/efibootmgr/issues/12 .
|
|
|
c9eda1 |
|
|
|
c9eda1 |
Signed-off-by: Peter Jones <pjones@redhat.com>
|
|
|
c9eda1 |
---
|
|
|
c9eda1 |
src/efibootmgr/efibootmgr.c | 94 +++++++++++++++++++++++++++++++++++----------
|
|
|
c9eda1 |
1 file changed, 73 insertions(+), 21 deletions(-)
|
|
|
c9eda1 |
|
|
|
c9eda1 |
diff --git a/src/efibootmgr/efibootmgr.c b/src/efibootmgr/efibootmgr.c
|
|
|
c9eda1 |
index f819b96..2b1ac47 100644
|
|
|
c9eda1 |
--- a/src/efibootmgr/efibootmgr.c
|
|
|
c9eda1 |
+++ b/src/efibootmgr/efibootmgr.c
|
|
|
c9eda1 |
@@ -1069,15 +1069,26 @@ parse_opts(int argc, char **argv)
|
|
|
c9eda1 |
case 'B':
|
|
|
c9eda1 |
opts.delete_boot = 1;
|
|
|
c9eda1 |
break;
|
|
|
c9eda1 |
- case 'b':
|
|
|
c9eda1 |
- rc = sscanf(optarg, "%X", &num);
|
|
|
c9eda1 |
- if (rc == 1 && num < 0xffff) {
|
|
|
c9eda1 |
- opts.bootnum = num;
|
|
|
c9eda1 |
- } else {
|
|
|
c9eda1 |
- fprintf (stderr,"invalid hex value %s\n",optarg);
|
|
|
c9eda1 |
+ case 'b': {
|
|
|
c9eda1 |
+ char *endptr = NULL;
|
|
|
c9eda1 |
+ unsigned long result;
|
|
|
c9eda1 |
+ result = strtoul(optarg, &endptr, 16);
|
|
|
c9eda1 |
+ if ((result == ULONG_MAX && errno == ERANGE) ||
|
|
|
c9eda1 |
+ (endptr && *endptr != '\0')) {
|
|
|
c9eda1 |
+ print_error_arrow("Invalid bootnum value",
|
|
|
c9eda1 |
+ optarg,
|
|
|
c9eda1 |
+ (intptr_t)endptr - (intptr_t)optarg);
|
|
|
c9eda1 |
+ exit(1);
|
|
|
c9eda1 |
+ }
|
|
|
c9eda1 |
+ if (result > 0xffff) {
|
|
|
c9eda1 |
+ fprintf(stderr, "Invalid bootnum value: %lX\n",
|
|
|
c9eda1 |
+ result);
|
|
|
c9eda1 |
exit(1);
|
|
|
c9eda1 |
}
|
|
|
c9eda1 |
+
|
|
|
c9eda1 |
+ opts.bootnum = num;
|
|
|
c9eda1 |
break;
|
|
|
c9eda1 |
+ }
|
|
|
c9eda1 |
case 'c':
|
|
|
c9eda1 |
opts.create = 1;
|
|
|
c9eda1 |
break;
|
|
|
c9eda1 |
@@ -1112,14 +1123,26 @@ parse_opts(int argc, char **argv)
|
|
|
c9eda1 |
exit(0);
|
|
|
c9eda1 |
break;
|
|
|
c9eda1 |
|
|
|
c9eda1 |
- case 'H':
|
|
|
c9eda1 |
- rc = sscanf(optarg, "%x", &num);
|
|
|
c9eda1 |
- if (rc == 1) opts.acpi_hid = num;
|
|
|
c9eda1 |
- else {
|
|
|
c9eda1 |
- fprintf (stderr,"invalid hex value %s\n",optarg);
|
|
|
c9eda1 |
+ case 'H': {
|
|
|
c9eda1 |
+ char *endptr = NULL;
|
|
|
c9eda1 |
+ unsigned long result;
|
|
|
c9eda1 |
+ result = strtoul(optarg, &endptr, 16);
|
|
|
c9eda1 |
+ if ((result == ULONG_MAX && errno == ERANGE) ||
|
|
|
c9eda1 |
+ (endptr && *endptr != '\0')) {
|
|
|
c9eda1 |
+ print_error_arrow("Invalid ACPI_HID value",
|
|
|
c9eda1 |
+ optarg,
|
|
|
c9eda1 |
+ (intptr_t)endptr - (intptr_t)optarg);
|
|
|
c9eda1 |
+ exit(1);
|
|
|
c9eda1 |
+ }
|
|
|
c9eda1 |
+ if (result > 0xffff) {
|
|
|
c9eda1 |
+ fprintf(stderr, "Invalid ACPI_HID value: %lX\n",
|
|
|
c9eda1 |
+ result);
|
|
|
c9eda1 |
exit(1);
|
|
|
c9eda1 |
}
|
|
|
c9eda1 |
+
|
|
|
c9eda1 |
+ opts.acpi_hid = num;
|
|
|
c9eda1 |
break;
|
|
|
c9eda1 |
+ }
|
|
|
c9eda1 |
case 'i':
|
|
|
c9eda1 |
opts.iface = optarg;
|
|
|
c9eda1 |
break;
|
|
|
c9eda1 |
@@ -1135,14 +1158,31 @@ parse_opts(int argc, char **argv)
|
|
|
c9eda1 |
case 'N':
|
|
|
c9eda1 |
opts.delete_bootnext = 1;
|
|
|
c9eda1 |
break;
|
|
|
c9eda1 |
- case 'n':
|
|
|
c9eda1 |
- rc = sscanf(optarg, "%x", &num);
|
|
|
c9eda1 |
- if (rc == 1) opts.bootnext = num;
|
|
|
c9eda1 |
- else {
|
|
|
c9eda1 |
- fprintf (stderr,"invalid hex value %s\n",optarg);
|
|
|
c9eda1 |
+ case 'n': {
|
|
|
c9eda1 |
+ char *endptr = NULL;
|
|
|
c9eda1 |
+ unsigned long result;
|
|
|
c9eda1 |
+ result = strtoul(optarg, &endptr, 16);
|
|
|
c9eda1 |
+ if ((result == ULONG_MAX && errno == ERANGE) ||
|
|
|
c9eda1 |
+ (endptr && *endptr != '\0')) {
|
|
|
c9eda1 |
+ print_error_arrow("Invalid BootNext value",
|
|
|
c9eda1 |
+ optarg,
|
|
|
c9eda1 |
+ (intptr_t)endptr - (intptr_t)optarg);
|
|
|
c9eda1 |
+ exit(1);
|
|
|
c9eda1 |
+ }
|
|
|
c9eda1 |
+ if (result > 0xffff) {
|
|
|
c9eda1 |
+ fprintf(stderr, "Invalid BootNext value: %lX\n",
|
|
|
c9eda1 |
+ result);
|
|
|
c9eda1 |
exit(1);
|
|
|
c9eda1 |
}
|
|
|
c9eda1 |
+ if (!is_current_boot_entry(result)) {
|
|
|
c9eda1 |
+ fprintf(stderr,
|
|
|
c9eda1 |
+ "Boot entry %04lX does not exist\n",
|
|
|
c9eda1 |
+ result);
|
|
|
c9eda1 |
+ exit(1);
|
|
|
c9eda1 |
+ }
|
|
|
c9eda1 |
+ opts.bootnext = result;
|
|
|
c9eda1 |
break;
|
|
|
c9eda1 |
+ }
|
|
|
c9eda1 |
case 'o':
|
|
|
c9eda1 |
opts.bootorder = optarg;
|
|
|
c9eda1 |
break;
|
|
|
c9eda1 |
@@ -1178,14 +1218,26 @@ parse_opts(int argc, char **argv)
|
|
|
c9eda1 |
opts.unicode = 1;
|
|
|
c9eda1 |
break;
|
|
|
c9eda1 |
|
|
|
c9eda1 |
- case 'U':
|
|
|
c9eda1 |
- rc = sscanf(optarg, "%x", &num);
|
|
|
c9eda1 |
- if (rc == 1) opts.acpi_uid = num;
|
|
|
c9eda1 |
- else {
|
|
|
c9eda1 |
- fprintf (stderr,"invalid hex value %s\n",optarg);
|
|
|
c9eda1 |
+ case 'U': {
|
|
|
c9eda1 |
+ char *endptr = NULL;
|
|
|
c9eda1 |
+ unsigned long result;
|
|
|
c9eda1 |
+ result = strtoul(optarg, &endptr, 16);
|
|
|
c9eda1 |
+ if ((result == ULONG_MAX && errno == ERANGE) ||
|
|
|
c9eda1 |
+ (endptr && *endptr != '\0')) {
|
|
|
c9eda1 |
+ print_error_arrow("Invalid ACPI_UID value",
|
|
|
c9eda1 |
+ optarg,
|
|
|
c9eda1 |
+ (intptr_t)endptr - (intptr_t)optarg);
|
|
|
c9eda1 |
+ exit(1);
|
|
|
c9eda1 |
+ }
|
|
|
c9eda1 |
+ if (result > 0xffff) {
|
|
|
c9eda1 |
+ fprintf(stderr, "Invalid ACPI_UID value: %lX\n",
|
|
|
c9eda1 |
+ result);
|
|
|
c9eda1 |
exit(1);
|
|
|
c9eda1 |
}
|
|
|
c9eda1 |
+
|
|
|
c9eda1 |
+ opts.acpi_uid = num;
|
|
|
c9eda1 |
break;
|
|
|
c9eda1 |
+ }
|
|
|
c9eda1 |
case 'v':
|
|
|
c9eda1 |
opts.verbose = 1;
|
|
|
c9eda1 |
if (optarg) {
|
|
|
c9eda1 |
--
|
|
|
c9eda1 |
2.4.3
|
|
|
c9eda1 |
|