git: f6c74bacf5e7 - stable/13 - elfctl: fix -e invalid operation error handling
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Fri, 18 Feb 2022 01:50:58 UTC
The branch stable/13 has been updated by emaste:
URL: https://cgit.FreeBSD.org/src/commit/?id=f6c74bacf5e73f41e7b2d3ba1a66d1d43f7ea785
commit f6c74bacf5e73f41e7b2d3ba1a66d1d43f7ea785
Author: Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2022-02-15 03:30:29 +0000
Commit: Ed Maste <emaste@FreeBSD.org>
CommitDate: 2022-02-18 00:31:26 +0000
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)
---
usr.bin/elfctl/elfctl.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/usr.bin/elfctl/elfctl.c b/usr.bin/elfctl/elfctl.c
index de14551f76d9..9463372f6740 100644
--- a/usr.bin/elfctl/elfctl.c
+++ b/usr.bin/elfctl/elfctl.c
@@ -230,6 +230,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) {
@@ -278,10 +282,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);
}