#4877 assigned defect

sptests/spsysinit01 sem_open call only has 3 parameters with O_CREAT flag

Reported by: Lucian-Raul Silistru Owned by: Sebastian Huber
Priority: normal Milestone: 5.4
Component: test Version: 5
Severity: normal Keywords:
Cc: Blocked By:


When calling sem_open with the O_CREAT flag the sem_open function requires 4 parameters. It will:
value = va_arg(args, unsigned int);
so the "value" argument will be randomly chosen.

sem_open can fail if the random value is not a valid semaphore value, failing the test.

Change History (4)

comment:1 Changed on 03/13/23 at 13:31:05 by Joel Sherrill

Resolution: invalid
Status: newclosed

This is an error on the caller's part. Per https://pubs.opengroup.org/onlinepubs/9699919799/functions/sem_open.html, the fourth argument is required if you include O_CREAT. Since you did not explicitly pass a value, the result is undefined.

This flag is used to create a semaphore if it does not already exist. If O_CREAT is set and the semaphore already exists, then O_CREAT has no effect, except as noted under O_EXCL. Otherwise, sem_open() creates a named semaphore. The O_CREAT flag requires a third and a fourth argument: mode, which is of type mode_t, and value, which is of type unsigned. The semaphore is created with an initial value of value. Valid initial values for semaphores are less than or equal to {SEM_VALUE_MAX}.

comment:2 Changed on 03/13/23 at 13:35:06 by Lucian-Raul Silistru

It's the RTEMS test spstests/spsysinit01 that calls sem_open with only 3 arguments (line 911 in init.c - master branch on github right now).

comment:3 Changed on 03/13/23 at 14:28:50 by Sebastian Huber

Milestone: 5.4
Resolution: invalid
Status: closedreopened

Thanks, you found the reason for a sporadic test failure which is on my TODO list for a long time.

comment:4 Changed on 03/13/23 at 14:29:09 by Sebastian Huber

Owner: changed from joel@… to Sebastian Huber
Status: reopenedassigned
Note: See TracTickets for help on using tickets.