diff options
| author | Ed Maste <emaste@FreeBSD.org> | 2021-01-22 17:22:35 +0000 |
|---|---|---|
| committer | Ed Maste <emaste@FreeBSD.org> | 2021-01-26 14:46:00 +0000 |
| commit | d7e23b5cdd8465bd50f88b1e38cb695a361a26f5 (patch) | |
| tree | 6a8839abccff1be79a3fa6987afa5a6215e0b92a /usr.bin/elfctl | |
| parent | 49d3dcb041f058880486e3489ca79c9476ac7abf (diff) | |
Diffstat (limited to 'usr.bin/elfctl')
| -rw-r--r-- | usr.bin/elfctl/elfctl.1 | 15 | ||||
| -rw-r--r-- | usr.bin/elfctl/elfctl.c | 26 |
2 files changed, 36 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 efc993302c60..15b35a5fec4b 100644 --- a/usr.bin/elfctl/elfctl.c +++ b/usr.bin/elfctl/elfctl.c @@ -33,12 +33,15 @@ #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> #include <libelf.h> #include <stdbool.h> +#include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -246,9 +249,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; + unsigned long long val; + + errno = 0; + val = strtoll(feature, &eptr, 0); + if (eptr == feature || *eptr != '\0') + errno = EINVAL; + else if (val > UINT32_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); + } } } |
