From 9291c5c31a7dd325e7366e5db777c0b4882b9abd Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sun, 13 Apr 2025 23:17:06 +0200 Subject: [PATCH] getlogin tests: Avoid writing to a literal string. * tests/test-getlogin.c: Include xalloc.h. (main): Pass a writable string to putenv(). * modules/getlogin-tests (Depends-on): Add xalloc. (Makefile.am): Link the program with libintl when needed. --- ChangeLog | 8 ++++++++ modules/getlogin-tests | 3 ++- tests/test-getlogin.c | 5 ++++- 3 files changed, 14 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index c766cc9cca..1547bed51e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2025-04-13 Bruno Haible + + getlogin tests: Avoid writing to a literal string. + * tests/test-getlogin.c: Include xalloc.h. + (main): Pass a writable string to putenv(). + * modules/getlogin-tests (Depends-on): Add xalloc. + (Makefile.am): Link the program with libintl when needed. + 2025-04-13 Bruno Haible vasnprintf: Optimize last commit. diff --git a/modules/getlogin-tests b/modules/getlogin-tests index 8637b2ea7e..6484ffe251 100644 --- a/modules/getlogin-tests +++ b/modules/getlogin-tests @@ -6,10 +6,11 @@ tests/macros.h Depends-on: bool +xalloc configure.ac: Makefile.am: TESTS += test-getlogin check_PROGRAMS += test-getlogin -test_getlogin_LDADD = $(LDADD) $(GETLOGIN_LIB) +test_getlogin_LDADD = $(LDADD) @LIBINTL@ $(GETLOGIN_LIB) diff --git a/tests/test-getlogin.c b/tests/test-getlogin.c index 431844bd71..11f67de542 100644 --- a/tests/test-getlogin.c +++ b/tests/test-getlogin.c @@ -18,11 +18,14 @@ #include +/* Specification. */ #include #include "signature.h" SIGNATURE_CHECK (getlogin, char *, (void)); +#include "xalloc.h" + #include "test-getlogin.h" int @@ -42,7 +45,7 @@ main (void) test_getlogin_result (buf, err); /* Check that getlogin() does not merely return getenv ("LOGNAME"). */ - putenv ("LOGNAME=ygvfibmslhkmvoetbrcegzwydorcke"); + putenv (xstrdup ("LOGNAME=ygvfibmslhkmvoetbrcegzwydorcke")); buf = getlogin (); ASSERT (!(buf != NULL && strcmp (buf, "ygvfibmslhkmvoetbrcegzwydorcke") == 0)); -- 2.39.5