From: Bruno Haible Date: Sun, 13 Apr 2025 21:18:10 +0000 (+0200) Subject: getlogin_r tests: Avoid writing to a literal string. X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=ebff098c2e7252ffc4c926eb33a87bba9c035e3c;p=gnulib.git getlogin_r tests: Avoid writing to a literal string. * tests/test-getlogin_r.c: Include xalloc.h. (main): Pass a writable string to putenv(). * modules/getlogin_r-tests (Depends-on): Add xalloc. (Makefile.am): Link the program with libintl when needed. --- diff --git a/ChangeLog b/ChangeLog index 1547bed51e..2ea548d13f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,11 @@ 2025-04-13 Bruno Haible + getlogin_r tests: Avoid writing to a literal string. + * tests/test-getlogin_r.c: Include xalloc.h. + (main): Pass a writable string to putenv(). + * modules/getlogin_r-tests (Depends-on): Add xalloc. + (Makefile.am): Link the program with libintl when needed. + getlogin tests: Avoid writing to a literal string. * tests/test-getlogin.c: Include xalloc.h. (main): Pass a writable string to putenv(). diff --git a/modules/getlogin_r-tests b/modules/getlogin_r-tests index 8fefa059bc..3cddb65584 100644 --- a/modules/getlogin_r-tests +++ b/modules/getlogin_r-tests @@ -6,10 +6,11 @@ tests/macros.h Depends-on: bool +xalloc configure.ac: Makefile.am: TESTS += test-getlogin_r check_PROGRAMS += test-getlogin_r -test_getlogin_r_LDADD = $(LDADD) $(GETLOGIN_LIB) +test_getlogin_r_LDADD = $(LDADD) @LIBINTL@ $(GETLOGIN_LIB) diff --git a/tests/test-getlogin_r.c b/tests/test-getlogin_r.c index 3674195e55..e27e23da23 100644 --- a/tests/test-getlogin_r.c +++ b/tests/test-getlogin_r.c @@ -18,6 +18,7 @@ #include +/* Specification. */ #include #include "signature.h" @@ -25,6 +26,8 @@ SIGNATURE_CHECK (getlogin_r, int, (char *, size_t)); #endif +#include "xalloc.h" + #include "test-getlogin.h" int @@ -69,7 +72,7 @@ main (void) } /* Check that getlogin_r() does not merely return getenv ("LOGNAME"). */ - putenv ("LOGNAME=ygvfibmslhkmvoetbrcegzwydorcke"); + putenv (xstrdup ("LOGNAME=ygvfibmslhkmvoetbrcegzwydorcke")); err = getlogin_r (buf, sizeof buf); ASSERT (!(err == 0 && strcmp (buf, "ygvfibmslhkmvoetbrcegzwydorcke") == 0));