NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

kern/56549: consecutive sem_open() do not return the same address



>Number:         56549
>Category:       kern
>Synopsis:       consecutive sem_open() do not return the same address
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    kern-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Dec 14 15:40:00 +0000 2021
>Originator:     Thomas Klausner
>Release:        NetBSD 9.99.92
>Organization:

>Environment:
	
	
Architecture: x86_64
Machine: amd64
>Description:
sem_open(3) claims:

     If the same name argument is given to multiple calls to
     sem_open() by the same process without an intervening call to
     sem_close(), the same address is returned each time.

This is not happening.
>How-To-Repeat:
Try multiple sem_open calls, see that they return different values.

Index: t_sem.c
===================================================================
RCS file: /cvsroot/src/tests/lib/librt/t_sem.c,v
retrieving revision 1.5
diff -u -r1.5 t_sem.c
--- t_sem.c	14 May 2020 08:34:19 -0000	1.5
+++ t_sem.c	14 Dec 2021 15:38:47 -0000
@@ -313,6 +313,31 @@
 	(void)sem_unlink("/sem_c");
 }
 
+ATF_TC_WITH_CLEANUP(sem_open_address);
+ATF_TC_HEAD(sem_open_address, tc)
+{
+	atf_tc_set_md_var(tc, "descr", "Validate that multiple sem_open calls "
+	    "return the same address");
+}
+ATF_TC_BODY(sem_open_address, tc)
+{
+	sem_t *sem, *sem2, *sem3;
+	sem = sem_open("/sem_d", O_CREAT | O_EXCL, 0777, 0);
+	ATF_REQUIRE(sem != SEM_FAILED);
+	sem2 = sem_open("/sem_d", O_CREAT | O_EXCL, 0777, 0);
+	ATF_REQUIRE(sem2 == SEM_FAILED && errno == EEXIST);
+	sem3 = sem_open("/sem_d", 0);
+	ATF_REQUIRE(sem3 != SEM_FAILED);
+	ATF_REQUIRE(sem == sem3);
+	ATF_REQUIRE_EQ(sem_close(sem3), 0);
+	ATF_REQUIRE_EQ(sem_close(sem), 0);
+	ATF_REQUIRE_EQ(sem_unlink("/sem_d"), 0);
+}
+ATF_TC_CLEANUP(sem_open_address, tc)
+{
+	(void)sem_unlink("/sem_d");
+}
+
 ATF_TP_ADD_TCS(tp)
 {
 
@@ -320,6 +345,7 @@
 	ATF_TP_ADD_TC(tp, child);
 	ATF_TP_ADD_TC(tp, pshared);
 	ATF_TP_ADD_TC(tp, invalid_ops);
+	ATF_TP_ADD_TC(tp, sem_open_address);
 
 	return atf_no_error();
 }
Fails with:
tc-end: 1639496081.591387, sem_open_address, failed, t_sem.c:331: sem == sem3 not met

>Fix:
Not provided.

>Unformatted:
 	
 	


Home | Main Index | Thread Index | Old Index