[LTP] openposix: timer_*/speculative: Handle SIGSEGV on old glibc
linuxtestproject.agent@gmail.com
linuxtestproject.agent@gmail.com
Tue Sep 29 19:50:03 CEST 2026
Hi Avinesh,
On Tue Sep 29 14:47:54 2026 +0200, Avinesh Kumar wrote:
> openposix: timer_*/speculative: Handle SIGSEGV on old glibc
> diff --git a/testcases/open_posix_testsuite/conformance/interfaces/timer_delete/speculative/5-1.c b/testcases/open_posix_testsuite/conformance/interfaces/timer_delete/speculative/5-1.c
> index dce9277b5..c7a94e144 100644
> --- a/testcases/open_posix_testsuite/conformance/interfaces/timer_delete/speculative/5-1.c
> +++ b/testcases/open_posix_testsuite/conformance/interfaces/timer_delete/speculative/5-1.c
> @@ -13,13 +13,31 @@
> #include <time.h>
> #include <stdio.h>
> #include <errno.h>
> +#include <signal.h>
> +#include <unistd.h>
> #include "posixtest.h"
>
> #define BOGUSTIMERID 99999
>
> +/*
> + * timerid is not a valid timer ID; POSIX defines no required behavior
> + * here (EINVAL is only a recommendation), so SIGSEGV is an equally
> + * valid outcome.
> + */
> +static void sigsegv_handler(int signum PTS_ATTRIBUTE_UNUSED)
> +{
> + PTS_WRITE_MSG("Got SIGSEGV when calling timer_delete() with an invalid timer ID\n");
> + PTS_WRITE_MSG("Test PASSED\n");
> + _exit(PTS_PASS);
> +}
> +
> int test_main(int argc PTS_ATTRIBUTE_UNUSED, char **argv PTS_ATTRIBUTE_UNUSED)
> {
> timer_t tid = (timer_t)BOGUSTIMERID;
> + struct sigaction sa = { .sa_handler = sigsegv_handler };
> +
> + sigfillset(&sa.sa_mask);
> + sigaction(SIGSEGV, &sa, NULL);
Catching SIGSEGV and exiting with PTS_PASS circumvents the check for
errno=EINVAL and masks faults instead of verifying the interface. Use
"static int tval = BOGUSTIMERID; timer_t tid = (timer_t)&tval;" without a
signal handler instead; this provides a readable pointer for older glibc
(<= 2.31) while keeping the MSB clear so glibc >= 2.34 and musl do not
treat it as a SIGEV_THREAD timer.
> diff --git a/testcases/open_posix_testsuite/conformance/interfaces/timer_getoverrun/speculative/6-1.c b/testcases/open_posix_testsuite/conformance/interfaces/timer_getoverrun/speculative/6-1.c
> index 3a8f1448d..7861e99d4 100644
> --- a/testcases/open_posix_testsuite/conformance/interfaces/timer_getoverrun/speculative/6-1.c
> +++ b/testcases/open_posix_testsuite/conformance/interfaces/timer_getoverrun/speculative/6-1.c
> @@ -13,13 +13,31 @@
> #include <time.h>
> #include <stdio.h>
> #include <errno.h>
> +#include <signal.h>
> +#include <unistd.h>
> #include "posixtest.h"
>
> #define BOGUSTID 9999
>
> +/*
> + * timerid is not a valid timer ID; POSIX defines no required behavior
> + * here (EINVAL is only a recommendation), so SIGSEGV is an equally
> + * valid outcome.
> + */
> +static void sigsegv_handler(int signum PTS_ATTRIBUTE_UNUSED)
> +{
> + PTS_WRITE_MSG("Got SIGSEGV when calling timer_getoverrun() with an invalid timer ID\n");
> + PTS_WRITE_MSG("Test PASSED\n");
> + _exit(PTS_PASS);
> +}
> +
> int test_main(int argc PTS_ATTRIBUTE_UNUSED, char **argv PTS_ATTRIBUTE_UNUSED)
> {
> timer_t tid = (timer_t)BOGUSTID;
> + struct sigaction sa = { .sa_handler = sigsegv_handler };
> +
> + sigfillset(&sa.sa_mask);
> + sigaction(SIGSEGV, &sa, NULL);
Same issue here; pass a pointer to a static int variable instead of
handling SIGSEGV.
> diff --git a/testcases/open_posix_testsuite/conformance/interfaces/timer_gettime/speculative/6-1.c b/testcases/open_posix_testsuite/conformance/interfaces/timer_gettime/speculative/6-1.c
> index 586b0ed3a..a3a9e080e 100644
> --- a/testcases/open_posix_testsuite/conformance/interfaces/timer_gettime/speculative/6-1.c
> +++ b/testcases/open_posix_testsuite/conformance/interfaces/timer_gettime/speculative/6-1.c
> @@ -13,14 +13,32 @@
> #include <time.h>
> #include <stdio.h>
> #include <errno.h>
> +#include <signal.h>
> +#include <unistd.h>
> #include "posixtest.h"
>
> #define BOGUSTID 9999
>
> +/*
> + * timerid is not a valid timer ID; POSIX defines no required behavior
> + * here (EINVAL is only a recommendation), so SIGSEGV is an equally
> + * valid outcome.
> + */
> +static void sigsegv_handler(int signum PTS_ATTRIBUTE_UNUSED)
> +{
> + PTS_WRITE_MSG("Got SIGSEGV when calling timer_gettime() with an invalid timer ID\n");
> + PTS_WRITE_MSG("Test PASSED\n");
> + _exit(PTS_PASS);
> +}
> +
> int test_main(int argc PTS_ATTRIBUTE_UNUSED, char **argv PTS_ATTRIBUTE_UNUSED)
> {
> struct itimerspec its;
> timer_t tid = (timer_t)BOGUSTID;
> + struct sigaction sa = { .sa_handler = sigsegv_handler };
> +
> + sigfillset(&sa.sa_mask);
> + sigaction(SIGSEGV, &sa, NULL);
Same issue here; pass a pointer to a static int variable instead of
handling SIGSEGV.
> diff --git a/testcases/open_posix_testsuite/conformance/interfaces/timer_settime/speculative/12-1.c b/testcases/open_posix_testsuite/conformance/interfaces/timer_settime/speculative/12-1.c
> index ac7f7bf24..953d585b8 100644
> --- a/testcases/open_posix_testsuite/conformance/interfaces/timer_settime/speculative/12-1.c
> +++ b/testcases/open_posix_testsuite/conformance/interfaces/timer_settime/speculative/12-1.c
> @@ -12,14 +12,33 @@
> #include <time.h>
> #include <stdio.h>
> #include <errno.h>
> +#include <signal.h>
> +#include <unistd.h>
> #include "posixtest.h"
>
> #define BOGUSTID 9999
>
> +/*
> + * timerid is not a valid timer ID; POSIX defines no required behavior
> + * here (EINVAL is only a recommendation), so SIGSEGV is an equally
> + * valid outcome.
> + */
> +static void sigsegv_handler(int signum PTS_ATTRIBUTE_UNUSED)
> +{
> + PTS_WRITE_MSG("Got SIGSEGV when calling timer_settime() with an invalid timer ID\n");
> + PTS_WRITE_MSG("Test PASSED\n");
> + _exit(PTS_PASS);
> +}
> +
> int test_main(int argc PTS_ATTRIBUTE_UNUSED, char **argv PTS_ATTRIBUTE_UNUSED)
> {
> struct itimerspec its;
> timer_t tid = (timer_t)BOGUSTID;
> + struct sigaction sa = { .sa_handler = sigsegv_handler };
> +
> + sigfillset(&sa.sa_mask);
> + sigaction(SIGSEGV, &sa, NULL);
Same issue here; pass a pointer to a static int variable instead of
handling SIGSEGV.
Verdict - Needs revision
---
Note:
The agent can sometimes produce false positives although often its
findings are genuine. If you find issues with the review, please
comment this email or ignore the suggestions.
Regards,
LTP AI Reviewer
More information about the ltp
mailing list