diff options
author | Flavio Cruz <flaviocruz@gmail.com> | 2025-02-09 22:37:56 -0500 |
---|---|---|
committer | Samuel Thibault <samuel.thibault@ens-lyon.org> | 2025-02-10 19:44:46 +0100 |
commit | da49165ea6ca9a759229becc5e269594a80b0976 (patch) | |
tree | 8c66e17315ebef8a2175ea9470a7e17174623de6 | |
parent | 6bcd7bf10062005a10c2a9d0dbbb7bdc995e5503 (diff) | |
download | glibc-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.c | 10 |
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) |