summaryrefslogtreecommitdiffstats
path: root/usr.bin/elfdump
diff options
context:
space:
mode:
authoremaste <emaste@FreeBSD.org>2016-12-09 21:07:03 +0000
committeremaste <emaste@FreeBSD.org>2016-12-09 21:07:03 +0000
commit634e5487e4f8f366e417665fc4c9e99a0376a0a2 (patch)
tree7da993c0a92ce051f326009de3c438e5d0cdf547 /usr.bin/elfdump
parent2900540a1dd655ba34886fb295d0e367cc008e76 (diff)
downloadFreeBSD-src-634e5487e4f8f366e417665fc4c9e99a0376a0a2.zip
FreeBSD-src-634e5487e4f8f366e417665fc4c9e99a0376a0a2.tar.gz
MFC r305951: elfdump: adjust stdout/stderr capabilities
stdio uses fstat and the TIOCGETA ioctl. Also collapse the cap_rights_limit and new cap_ioctls_limit calls into one if statement. Errors here are not actionable by the user and distinguishing stdout from stderr doesn't really have value.
Diffstat (limited to 'usr.bin/elfdump')
-rw-r--r--usr.bin/elfdump/elfdump.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/usr.bin/elfdump/elfdump.c b/usr.bin/elfdump/elfdump.c
index feb5ddd..eda56ce 100644
--- a/usr.bin/elfdump/elfdump.c
+++ b/usr.bin/elfdump/elfdump.c
@@ -44,6 +44,7 @@ __FBSDID("$FreeBSD$");
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <termios.h>
#include <unistd.h>
#define ED_DYN (1<<0)
@@ -504,6 +505,7 @@ main(int ac, char **av)
u_int64_t name;
u_int64_t type;
struct stat sb;
+ unsigned long cmd;
u_int flags;
Elf32_Ehdr *e;
void *p;
@@ -572,11 +574,13 @@ main(int ac, char **av)
if (cap_rights_limit(fd, &rights) < 0 && errno != ENOSYS)
err(1, "unable to limit rights for %s", *av);
close(STDIN_FILENO);
- cap_rights_init(&rights, CAP_WRITE);
- if (cap_rights_limit(STDOUT_FILENO, &rights) < 0 && errno != ENOSYS)
- err(1, "unable to limit rights for stdout");
- if (cap_rights_limit(STDERR_FILENO, &rights) < 0 && errno != ENOSYS)
- err(1, "unable to limit rights for stderr");
+ cap_rights_init(&rights, CAP_FSTAT, CAP_IOCTL, CAP_WRITE);
+ cmd = TIOCGETA; /* required by isatty(3) in printf(3) */
+ if ((cap_rights_limit(STDOUT_FILENO, &rights) < 0 && errno != ENOSYS) ||
+ (cap_ioctls_limit(STDOUT_FILENO, &cmd, 1) < 0 && errno != ENOSYS) ||
+ (cap_rights_limit(STDERR_FILENO, &rights) < 0 && errno != ENOSYS) ||
+ (cap_ioctls_limit(STDERR_FILENO, &cmd, 1) < 0 && errno != ENOSYS))
+ err(1, "unable to limit rights for stdout/stderr");
if (cap_enter() < 0 && errno != ENOSYS)
err(1, "unable to enter capability mode");
e = mmap(NULL, sb.st_size, PROT_READ, MAP_SHARED, fd, 0);
OpenPOWER on IntegriCloud