]> Savannah Git Hosting - gnulib.git/commitdiff
getlogin_r tests: Avoid writing to a literal string.
authorBruno Haible <bruno@clisp.org>
Sun, 13 Apr 2025 21:18:10 +0000 (23:18 +0200)
committerBruno Haible <bruno@clisp.org>
Sun, 13 Apr 2025 21:18:10 +0000 (23:18 +0200)
* 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.

ChangeLog
modules/getlogin_r-tests
tests/test-getlogin_r.c

index 1547bed51e647814374d5fe308a0afd47b931ab5..2ea548d13f696de37c282d5947fb6eb5a062733c 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2025-04-13  Bruno Haible  <bruno@clisp.org>
 
+       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().
index 8fefa059bc71f679d91dde1328f83ba8a701face..3cddb655846131477893e4062e4ec949b6eee21d 100644 (file)
@@ -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)
index 3674195e55fe443cd8d133ffdf4a1b4a05617c51..e27e23da2349b6cc9a5b259a4693309e8fffec95 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <config.h>
 
+/* Specification.  */
 #include <unistd.h>
 
 #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));