Module Name: src Committed By: jruoho Date: Mon Jul 18 04:29:37 UTC 2011
Modified Files: src/tests/lib/libc/sys: t_dup.c Log Message: Verify that dup2(2) and dup3(2) fail with EBADF if the "new descriptor" is specified to be larger than RLIMIT_NOFILE. To generate a diff of this commit: cvs rdiff -u -r1.4 -r1.5 src/tests/lib/libc/sys/t_dup.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/tests/lib/libc/sys/t_dup.c diff -u src/tests/lib/libc/sys/t_dup.c:1.4 src/tests/lib/libc/sys/t_dup.c:1.5 --- src/tests/lib/libc/sys/t_dup.c:1.4 Sat Jul 16 14:29:15 2011 +++ src/tests/lib/libc/sys/t_dup.c Mon Jul 18 04:29:37 2011 @@ -1,4 +1,4 @@ -/* $NetBSD: t_dup.c,v 1.4 2011/07/16 14:29:15 jruoho Exp $ */ +/* $NetBSD: t_dup.c,v 1.5 2011/07/18 04:29:37 jruoho Exp $ */ /*- * Copyright (c) 2011 The NetBSD Foundation, Inc. @@ -29,7 +29,7 @@ * POSSIBILITY OF SUCH DAMAGE. */ #include <sys/cdefs.h> -__RCSID("$NetBSD: t_dup.c,v 1.4 2011/07/16 14:29:15 jruoho Exp $"); +__RCSID("$NetBSD: t_dup.c,v 1.5 2011/07/18 04:29:37 jruoho Exp $"); #include <sys/resource.h> #include <sys/stat.h> @@ -158,6 +158,23 @@ (void)close(fd); } +ATF_TC(dup2_max); +ATF_TC_HEAD(dup2_max, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test dup2(2) against limits"); +} + +ATF_TC_BODY(dup2_max, tc) +{ + struct rlimit res; + + (void)memset(&res, 0, sizeof(struct rlimit)); + (void)getrlimit(RLIMIT_NOFILE, &res); + + errno = 0; + ATF_REQUIRE_ERRNO(EBADF, dup2(STDERR_FILENO, res.rlim_cur + 1) == -1); +} + ATF_TC_WITH_CLEANUP(dup2_mode); ATF_TC_HEAD(dup2_mode, tc) { @@ -209,6 +226,24 @@ (void)close(fd); } +ATF_TC(dup3_max); +ATF_TC_HEAD(dup3_max, tc) +{ + atf_tc_set_md_var(tc, "descr", "Test dup3(2) against limits"); +} + +ATF_TC_BODY(dup3_max, tc) +{ + struct rlimit res; + + (void)memset(&res, 0, sizeof(struct rlimit)); + (void)getrlimit(RLIMIT_NOFILE, &res); + + errno = 0; + ATF_REQUIRE_ERRNO(EBADF, dup3(STDERR_FILENO, + res.rlim_cur + 1, O_CLOEXEC) == -1); +} + ATF_TC_WITH_CLEANUP(dup3_mode); ATF_TC_HEAD(dup3_mode, tc) { @@ -341,8 +376,10 @@ ATF_TP_ADD_TC(tp, dup2_basic); ATF_TP_ADD_TC(tp, dup2_err); + ATF_TP_ADD_TC(tp, dup2_max); ATF_TP_ADD_TC(tp, dup2_mode); ATF_TP_ADD_TC(tp, dup3_err); + ATF_TP_ADD_TC(tp, dup3_max); ATF_TP_ADD_TC(tp, dup3_mode); ATF_TP_ADD_TC(tp, dup_err); ATF_TP_ADD_TC(tp, dup_max);