diff --git a/usr.bin/elfctl/elfctl.c b/usr.bin/elfctl/elfctl.c --- 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); @@ -222,9 +222,9 @@ } 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; @@ -236,8 +236,10 @@ 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; @@ -267,13 +269,16 @@ 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); + } } } } @@ -285,6 +290,7 @@ } else if (operation == '-') { *feature_val &= ~input; } + free(feature_tmp); return (true); }