aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEd Maste <emaste@FreeBSD.org>2021-01-22 17:22:35 +0000
committerEd Maste <emaste@FreeBSD.org>2021-01-22 19:38:52 +0000
commit86f33b5fcf6087bf4439881011b920ff99e6e300 (patch)
tree38c6275e0b8c8d98703e76c1abaef483ac90160a
parent57a543d8b85065f77e0b68162d09a03335970f90 (diff)
downloadsrc-86f33b5fcf6087bf4439881011b920ff99e6e300.tar.gz
src-86f33b5fcf6087bf4439881011b920ff99e6e300.zip
elfctl: allow features to be specified by value
This will allow elfctl on older releases to set bits that are not yet known there, so that the binary will have the correct settings applied if run on a later FreeBSD version. PR: 252629 (related) Suggested by: kib Reviewed by: gbe (manpage, earlier), kib MFC after: 3 days Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D28284
-rw-r--r--usr.bin/elfctl/elfctl.115
-rw-r--r--usr.bin/elfctl/elfctl.c25
2 files changed, 35 insertions, 5 deletions
diff --git a/usr.bin/elfctl/elfctl.1 b/usr.bin/elfctl/elfctl.1
index f93b558fdf0d..23e2dabea49c 100644
--- a/usr.bin/elfctl/elfctl.1
+++ b/usr.bin/elfctl/elfctl.1
@@ -26,7 +26,7 @@
.\"
.\" $FreeBSD$
.\"
-.Dd January 12, 2021
+.Dd January 22, 2021
.Dt ELFCTL 1
.Os
.Sh NAME
@@ -64,7 +64,8 @@ to turn on the features,
to turn off the features,
.Dq Li =
to only turn on the given features.
-A comma separated list of feature names follows the operation.
+A comma separated list of feature names or numeric values follows the
+operation.
.El
.Pp
If
@@ -86,6 +87,16 @@ command:
elfctl file
elfctl -e +aslr file
.Ed
+.Pp
+Features may be specified as numerical values:
+.Bd -literal -offset -indent
+elfctl -e =0x0001,0x0004 file
+.Ed
+.Pp
+Features may also be specified as a single combined value:
+.Bd -literal -offset -indent
+elfctl -e =0x5 file
+.Ed
.Sh HISTORY
.Nm
first appeared in
diff --git a/usr.bin/elfctl/elfctl.c b/usr.bin/elfctl/elfctl.c
index 20a2c5b95444..f641b63e32bd 100644
--- a/usr.bin/elfctl/elfctl.c
+++ b/usr.bin/elfctl/elfctl.c
@@ -33,7 +33,9 @@
#include <sys/endian.h>
#include <sys/stat.h>
+#include <ctype.h>
#include <err.h>
+#include <errno.h>
#include <fcntl.h>
#include <gelf.h>
#include <getopt.h>
@@ -245,9 +247,26 @@ convert_to_feature_val(char *feature_str, uint32_t *feature_val)
}
}
if (i == len) {
- warnx("%s is not a valid feature", feature);
- if (!iflag)
- return (false);
+ if (isdigit(feature[0])) {
+ char *eptr;
+ long val;
+
+ errno = 0;
+ val = strtol(feature, &eptr, 0);
+ if (eptr == feature || *eptr != '\0')
+ errno = EINVAL;
+ else if (val > UINT_MAX)
+ errno = ERANGE;
+ if (errno != 0) {
+ warn("%s invalid", feature);
+ return (false);
+ }
+ input != val;
+ } else {
+ warnx("%s is not a valid feature", feature);
+ if (!iflag)
+ return (false);
+ }
}
}