about summary refs log tree commit diff
path: root/debug/tst-fortify.c
diff options
context:
space:
mode:
authorFlorian Weimer <fweimer@redhat.com>2023-06-14 18:10:08 +0200
committerFlorian Weimer <fweimer@redhat.com>2023-06-14 18:10:08 +0200
commit454a20c8756c9c1d55419153255fc7692b3d2199 (patch)
treea65ad84288a247995183089f4400e4fd080ecc9d /debug/tst-fortify.c
parent7ba426a1115318fc11f4355f3161f35817a06ba4 (diff)
downloadglibc-454a20c8756c9c1d55419153255fc7692b3d2199.tar.gz
glibc-454a20c8756c9c1d55419153255fc7692b3d2199.tar.xz
glibc-454a20c8756c9c1d55419153255fc7692b3d2199.zip
Implement strlcpy and strlcat [BZ #178]
These functions are about to be added to POSIX, under Austin Group
issue 986.

The fortified strlcat implementation does not raise SIGABRT if the
destination buffer does not contain a null terminator, it just
inherits the non-failing regular strlcat behavior.

Reviewed-by: Siddhesh Poyarekar <siddhesh@sourceware.org>
Diffstat (limited to 'debug/tst-fortify.c')
-rw-r--r--debug/tst-fortify.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/debug/tst-fortify.c b/debug/tst-fortify.c
index 9f962f2a75..0f823a85d0 100644
--- a/debug/tst-fortify.c
+++ b/debug/tst-fortify.c
@@ -535,6 +535,20 @@ do_test (void)
   strncpy (a.buf1 + (O + 6), "X", l0 + 4);
   CHK_FAIL_END
 
+  CHK_FAIL_START
+  strlcpy (a.buf1 + (O + 6), "X", 4);
+  CHK_FAIL_END
+
+  CHK_FAIL_START
+  strlcpy (a.buf1 + (O + 6), "X", l0 + 4);
+  CHK_FAIL_END
+
+  {
+    char *volatile buf2 = buf;
+    if (strlcpy (buf2, "a", sizeof (buf) + 1) != 1)
+      FAIL ();
+  }
+
 # if !defined __cplusplus || defined __va_arg_pack
   CHK_FAIL_START
   sprintf (a.buf1 + (O + 7), "%d", num1);
@@ -558,6 +572,23 @@ do_test (void)
   CHK_FAIL_START
   strncat (a.buf1, "ZYXWV", l0 + 3);
   CHK_FAIL_END
+
+  memset (a.buf1, 0, sizeof (a.buf1));
+  CHK_FAIL_START
+  strlcat (a.buf1 + (O + 6), "X", 4);
+  CHK_FAIL_END
+
+  memset (a.buf1, 0, sizeof (a.buf1));
+  CHK_FAIL_START
+  strlcat (a.buf1 + (O + 6), "X", l0 + 4);
+  CHK_FAIL_END
+
+  {
+    buf[0] = '\0';
+    char *volatile buf2 = buf;
+    if (strlcat (buf2, "a", sizeof (buf) + 1) != 1)
+      FAIL ();
+  }
 #endif