diff options
| author | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2025-04-23 11:44:24 -0300 |
|---|---|---|
| committer | Adhemerval Zanella <adhemerval.zanella@linaro.org> | 2025-04-25 17:46:06 -0300 |
| commit | cbc2b52ac0c331291dbd0e50f75822c0e8a21874 (patch) | |
| tree | 32cf4e13cf9ab1138c495d18c8ec35b6bd88a08c | |
| parent | 69c2c8faf6476b75fbb6e7e021107f0d5e039255 (diff) | |
| download | glibc-cbc2b52ac0c331291dbd0e50f75822c0e8a21874.tar.xz glibc-cbc2b52ac0c331291dbd0e50f75822c0e8a21874.zip | |
stdlib: Adapt tst-environ to ubsan
The test explicits checks for passing a null argument to a
function with argument nonnull attribute.
| -rw-r--r-- | stdlib/tst-environ.c | 30 |
1 files changed, 19 insertions, 11 deletions
diff --git a/stdlib/tst-environ.c b/stdlib/tst-environ.c index d790f9bddf..6684cd1c5b 100644 --- a/stdlib/tst-environ.c +++ b/stdlib/tst-environ.c @@ -27,6 +27,24 @@ char putenv_val[100] = VAR "=some longer value"; static int +__attribute_disable_usbsan__ +check_null_argument (void) +{ + /* This deliberately tests supplying a null pointer to a function whose + argument is marked __attribute__ ((nonnull)). */ + DIAG_PUSH_NEEDS_COMMENT; + DIAG_IGNORE_NEEDS_COMMENT(5, "-Wnonnull"); + errno = 0; + if (unsetenv (NULL) >= 0 || errno != EINVAL) + { + puts ("unsetenv #1 failed"); + return 1; + } + DIAG_POP_NEEDS_COMMENT; + return 0; +} + +static int do_test (void) { int result = 0; @@ -189,17 +207,7 @@ do_test (void) result = 1; } - /* This deliberately tests supplying a null pointer to a function whose - argument is marked __attribute__ ((nonnull)). */ - DIAG_PUSH_NEEDS_COMMENT; - DIAG_IGNORE_NEEDS_COMMENT(5, "-Wnonnull"); - errno = 0; - if (unsetenv (NULL) >= 0 || errno != EINVAL) - { - puts ("unsetenv #1 failed"); - result = 1; - } - DIAG_POP_NEEDS_COMMENT; + result = check_null_argument (); errno = 0; if (unsetenv ("") >= 0 || errno != EINVAL) |
