aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlavio Cruz <flaviocruz@gmail.com>2025-02-09 22:37:56 -0500
committerSamuel Thibault <samuel.thibault@ens-lyon.org>2025-02-10 19:44:46 +0100
commitda49165ea6ca9a759229becc5e269594a80b0976 (patch)
tree8c66e17315ebef8a2175ea9470a7e17174623de6
parent6bcd7bf10062005a10c2a9d0dbbb7bdc995e5503 (diff)
downloadglibc-da49165ea6ca9a759229becc5e269594a80b0976.zip
glibc-da49165ea6ca9a759229becc5e269594a80b0976.tar.gz
glibc-da49165ea6ca9a759229becc5e269594a80b0976.tar.bz2
mig_strncpy: ensure destination string is null terminated
Message-ID: <xaqw66fuawxm5hzgjscfg2oyp6lxflm5tnbb7u253pw3gmdy4m@5z42mw2qz2l2>
-rw-r--r--mach/mig_strncpy.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/mach/mig_strncpy.c b/mach/mig_strncpy.c
index b0c001d..dbd0a08 100644
--- a/mach/mig_strncpy.c
+++ b/mach/mig_strncpy.c
@@ -6,6 +6,14 @@
vm_size_t
__mig_strncpy (char *dst, const char *src, vm_size_t len)
{
- return __stpncpy (dst, src, len) - dst;
+ if (len == 0)
+ return 0;
+
+ char *end = __stpncpy (dst, src, len - 1);
+ vm_size_t ret = end - dst;
+ /* Null terminate the string. */
+ if (ret == len - 1)
+ *end = '\0';
+ return ret;
}
weak_alias (__mig_strncpy, mig_strncpy)