mirror of
git://sourceware.org/git/glibc.git
synced 2025-02-23 13:09:58 +08:00
mig_strncpy: ensure destination string is null terminated
Message-ID: <xaqw66fuawxm5hzgjscfg2oyp6lxflm5tnbb7u253pw3gmdy4m@5z42mw2qz2l2>
This commit is contained in:
parent
6bcd7bf100
commit
da49165ea6
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user