From: GNU Libc Maintainers Date: Wed, 18 Jun 2025 04:49:31 +0000 (+0200) Subject: git-mig-strncpy X-Git-Tag: archive/raspbian/2.41-9+rpi1^2~58 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=c83b2d43ae350b7c34d5a483cdd74a05f24e4c82;p=glibc.git git-mig-strncpy commit da49165ea6ca9a759229becc5e269594a80b0976 Author: Flavio Cruz Date: Sun Feb 9 22:37:56 2025 -0500 mig_strncpy: ensure destination string is null terminated Message-ID: Gbp-Pq: Topic hurd-i386 Gbp-Pq: Name git-mig-strncpy.diff --- diff --git a/mach/mig_strncpy.c b/mach/mig_strncpy.c index b0c001d77..dbd0a08e5 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)