From: Flavio Cruz Date: Mon, 10 Feb 2025 03:37:56 +0000 (-0500) Subject: mig_strncpy: ensure destination string is null terminated X-Git-Tag: glibc-2.42~511 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=da49165ea6ca9a759229becc5e269594a80b0976;p=thirdparty%2Fglibc.git mig_strncpy: ensure destination string is null terminated Message-ID: --- diff --git a/mach/mig_strncpy.c b/mach/mig_strncpy.c index b0c001d775..dbd0a08e56 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)