PERFORCE change 163978 for review
Robert Watson
rwatson at FreeBSD.org
Wed Jun 10 11:46:46 UTC 2009
http://perforce.freebsd.org/chv.cgi?CH=163978
Change 163978 by rwatson at rwatson_freebsd_capabilities on 2009/06/10 11:46:38
Assymptotically approach correctness.
Affected files ...
.. //depot/projects/trustedbsd/capabilities/src/lib/libcapability/libcapability_host.c#3 edit
Differences ...
==== //depot/projects/trustedbsd/capabilities/src/lib/libcapability/libcapability_host.c#3 (text+ko) ====
@@ -30,7 +30,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $P4: //depot/projects/trustedbsd/capabilities/src/lib/libcapability/libcapability_host.c#2 $
+ * $P4: //depot/projects/trustedbsd/capabilities/src/lib/libcapability/libcapability_host.c#3 $
*/
#include <sys/types.h>
@@ -92,15 +92,31 @@
* number.
*/
static int
-lch_installfds(int fd_count, int *fds)
+lch_installfds(u_int fd_count, int *fds)
{
- int i;
+ u_int i;
+ int highestfd;
+
+ if (fd_count == 0)
+ return (0);
+
+ /*
+ * Identify the highest source file descriptor we care about so that
+ * when we play the dup2() rearranging game, we don't overwrite any
+ * we care about.
+ */
+ highestfd = fds[0];
+ for (i = 1; i < fd_count; i++) {
+ if (fds[i] > highestfd)
+ highestfd = fds[i];
+ }
+ highestfd++;
/*
* First, move all our descriptors up the range.
*/
for (i = 0; i < fd_count; i++) {
- if (dup2(fds[i], fd_count + i) < 0)
+ if (dup2(fds[i], highestfd + i) < 0)
return (-1);
}
@@ -108,7 +124,7 @@
* Now put them back.
*/
for (i = 0; i < fd_count; i++) {
- if (dup2(fd_count + i, fds[i]) < 0)
+ if (dup2(highestfd + i, i) < 0)
return (-1);
}
More information about the p4-projects
mailing list