Fix handling of rights on stdio streams.
authorMark Johnston <markj@FreeBSD.org>
Thu, 17 Jan 2019 17:36:18 +0000 (17:36 +0000)
committerMark Johnston <markj@FreeBSD.org>
Thu, 17 Jan 2019 17:36:18 +0000 (17:36 +0000)
commite6de40fa7942abfdc0d3344c93f92883ecef3e67
tree49042fe300113d995224508fbb43a4b9f27488b6
parentc9cf7cb85b3ace873fa934631adeaf1edb5e3a4c
Fix handling of rights on stdio streams.

- Limit rights on stdio before opening input files.  Otherwise, open()
  may return one of the standard descriptors and we end up limiting
  rights such that we cannot read from one of the input files.
- Use caph_limit_stdio(), which suppresses EBADF, to ensure that
  we don't emit an error if one of the stdio streams is closed.
- Don't bother further limiting rights on stdin when stdin isn't going
  to be used.  Doing so correctly requires checking for a number of
  edge cases, and it doesn't provide any significant benefit.

PR: 234885
Reviewed by: oshogbo
MFC after: 3 days
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D18860
usr.bin/cmp/cmp.c