aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Maste <emaste@FreeBSD.org>2022-02-15 03:44:01 +0000
committerEd Maste <emaste@FreeBSD.org>2022-02-18 00:33:47 +0000
commitd3cbb4745a13d5155597e66281efa05cb6a7c72a (patch)
tree6021d52072ed01a793c81fce9a424900d46e02c3
parenta528bad95e0c80fe612051076d53b8bc8283e239 (diff)
elfctl: fix operations with multiple features on multiple files
Previously an invocation like elfctl -e +feature1,feature2 file1 file2 would set both feature flags in file 1 but only feature1 in file2 (due to the string being modified by strsep()). Reported by: jrm Tested by: jrm MFC after: 3 days Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D34283 (cherry picked from commit 82b611ed18e6bfaeadf152ef9216230548c25a8a)
-rw-r--r--usr.bin/elfctl/elfctl.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/usr.bin/elfctl/elfctl.c b/usr.bin/elfctl/elfctl.c
index b4482f82e7ef..eeade6ac371c 100644
--- a/usr.bin/elfctl/elfctl.c
+++ b/usr.bin/elfctl/elfctl.c
@@ -51,7 +51,7 @@
__FBSDID("$FreeBSD$");
-static bool convert_to_feature_val(char *, uint32_t *);
+static bool convert_to_feature_val(const char *, uint32_t *);
static bool edit_file_features(Elf *, int, int, char *, bool);
static bool get_file_features(Elf *, int, int, uint32_t *, uint64_t *, bool);
static void print_features(void);
@@ -226,9 +226,9 @@ usage(void)
}
static bool
-convert_to_feature_val(char *feature_str, uint32_t *feature_val)
+convert_to_feature_val(const char *feature_str, uint32_t *feature_val)
{
- char *feature;
+ char *feature, *feature_tmp;
int i, len;
uint32_t input;
char operation;
@@ -240,8 +240,10 @@ convert_to_feature_val(char *feature_str, uint32_t *feature_val)
if (operation != '+' && operation != '-' && operation != '=')
errx(1, "'%c' not an operator - use '+', '-', '='", operation);
+ if ((feature_tmp = strdup(feature_str)) == NULL)
+ err(1, "strdup");
len = nitems(featurelist);
- while ((feature = strsep(&feature_str, ",")) != NULL) {
+ while ((feature = strsep(&feature_tmp, ",")) != NULL) {
for (i = 0; i < len; ++i) {
if (strcmp(featurelist[i].alias, feature) == 0) {
input |= featurelist[i].value;
@@ -271,13 +273,16 @@ convert_to_feature_val(char *feature_str, uint32_t *feature_val)
errno = ERANGE;
if (errno != 0) {
warn("%s invalid", feature);
+ free(feature_tmp);
return (false);
}
input |= val;
} else {
warnx("%s is not a valid feature", feature);
- if (!iflag)
+ if (!iflag) {
+ free(feature_tmp);
return (false);
+ }
}
}
}
@@ -289,6 +294,7 @@ convert_to_feature_val(char *feature_str, uint32_t *feature_val)
} else if (operation == '-') {
*feature_val &= ~input;
}
+ free(feature_tmp);
return (true);
}