aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Maste <emaste@FreeBSD.org>2022-02-15 03:30:29 +0000
committerEd Maste <emaste@FreeBSD.org>2022-02-18 00:33:47 +0000
commitbbb92ab05fa2d039905ef988ca31b4356b01d964 (patch)
tree8511dac99d866898dfced270b8e5da8ef1622267
parent4328d67d254229e11c1cac1e23c65aa8de62c37c (diff)
elfctl: fix -e invalid operation error handling
Validate the operation prior to parsing the feature string, so that e.g. -e 0x1 reports invalid operation '0' rather than invalid feature 'x11'. Also make it an error rather than a warning, so that it is not repeated if multiple files are specified. (Previously an invalid operation resulted in a segfault.) MFC after: 3 days Sponsored by: The FreeBSD Foundation (cherry picked from commit b8185579f457569640f714b6180522619c2f18ea)
-rw-r--r--usr.bin/elfctl/elfctl.c8
1 files changed, 4 insertions, 4 deletions
diff --git a/usr.bin/elfctl/elfctl.c b/usr.bin/elfctl/elfctl.c
index dbd39f612439..1042712f828a 100644
--- a/usr.bin/elfctl/elfctl.c
+++ b/usr.bin/elfctl/elfctl.c
@@ -234,6 +234,10 @@ convert_to_feature_val(char *feature_str, uint32_t *feature_val)
input = 0;
operation = *feature_str;
feature_str++;
+
+ if (operation != '+' && operation != '-' && operation != '=')
+ errx(1, "'%c' not an operator - use '+', '-', '='", operation);
+
len = nitems(featurelist);
while ((feature = strsep(&feature_str, ",")) != NULL) {
for (i = 0; i < len; ++i) {
@@ -282,10 +286,6 @@ convert_to_feature_val(char *feature_str, uint32_t *feature_val)
*feature_val = input;
} else if (operation == '-') {
*feature_val &= ~input;
- } else {
- warnx("'%c' not an operator - use '+', '-', '='",
- feature_str[0]);
- return (false);
}
return (true);
}