2022-01-01 10:54:23 -08:00
|
|
|
/* Copyright (C) 2004-2022 Free Software Foundation, Inc.
|
2004-10-18 04:17:19 +00:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-09 23:18:22 +00:00
|
|
|
License along with the GNU C Library; if not, see
|
2019-09-06 22:40:42 -07:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
2004-10-18 04:17:19 +00:00
|
|
|
|
2016-11-17 09:26:27 -05:00
|
|
|
#ifndef _BITS_STRING_FORTIFIED_H
|
|
|
|
|
#define _BITS_STRING_FORTIFIED_H 1
|
|
|
|
|
|
2004-10-18 04:17:19 +00:00
|
|
|
#ifndef _STRING_H
|
2016-11-17 09:26:27 -05:00
|
|
|
# error "Never use <bits/string_fortified.h> directly; include <string.h> instead."
|
2004-10-18 04:17:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
2012-04-29 15:34:20 +02:00
|
|
|
__fortify_function void *
|
2012-01-07 23:57:22 -05:00
|
|
|
__NTH (memcpy (void *__restrict __dest, const void *__restrict __src,
|
2007-09-15 02:38:04 +00:00
|
|
|
size_t __len))
|
|
|
|
|
{
|
2020-12-30 11:09:58 +05:30
|
|
|
return __builtin___memcpy_chk (__dest, __src, __len,
|
|
|
|
|
__glibc_objsize0 (__dest));
|
2007-09-15 02:38:04 +00:00
|
|
|
}
|
2004-10-18 04:17:19 +00:00
|
|
|
|
2012-04-29 15:34:20 +02:00
|
|
|
__fortify_function void *
|
2012-01-07 23:57:22 -05:00
|
|
|
__NTH (memmove (void *__dest, const void *__src, size_t __len))
|
2007-09-15 02:38:04 +00:00
|
|
|
{
|
2020-12-30 11:09:58 +05:30
|
|
|
return __builtin___memmove_chk (__dest, __src, __len,
|
|
|
|
|
__glibc_objsize0 (__dest));
|
2007-09-15 02:38:04 +00:00
|
|
|
}
|
2004-10-18 04:17:19 +00:00
|
|
|
|
|
|
|
|
#ifdef __USE_GNU
|
2012-04-29 15:34:20 +02:00
|
|
|
__fortify_function void *
|
2012-01-07 23:57:22 -05:00
|
|
|
__NTH (mempcpy (void *__restrict __dest, const void *__restrict __src,
|
2007-09-15 02:38:04 +00:00
|
|
|
size_t __len))
|
|
|
|
|
{
|
2020-12-30 11:09:58 +05:30
|
|
|
return __builtin___mempcpy_chk (__dest, __src, __len,
|
|
|
|
|
__glibc_objsize0 (__dest));
|
2007-09-15 02:38:04 +00:00
|
|
|
}
|
2004-10-18 04:17:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
2005-02-21 23:14:10 +00:00
|
|
|
/* The first two tests here help to catch a somewhat common problem
|
|
|
|
|
where the second and third parameter are transposed. This is
|
|
|
|
|
especially problematic if the intended fill value is zero. In this
|
|
|
|
|
case no work is done at all. We detect these problems by referring
|
|
|
|
|
non-existing functions. */
|
2012-04-29 15:34:20 +02:00
|
|
|
__fortify_function void *
|
2007-09-15 02:38:04 +00:00
|
|
|
__NTH (memset (void *__dest, int __ch, size_t __len))
|
|
|
|
|
{
|
2020-12-30 11:09:58 +05:30
|
|
|
return __builtin___memset_chk (__dest, __ch, __len,
|
|
|
|
|
__glibc_objsize0 (__dest));
|
2007-09-15 02:38:04 +00:00
|
|
|
}
|
2004-10-18 04:17:19 +00:00
|
|
|
|
2014-02-12 23:41:01 +00:00
|
|
|
#ifdef __USE_MISC
|
2017-01-05 10:07:24 -02:00
|
|
|
# include <bits/strings_fortified.h>
|
2017-01-06 11:05:27 -02:00
|
|
|
|
|
|
|
|
void __explicit_bzero_chk (void *__dest, size_t __len, size_t __destlen)
|
2021-10-12 12:29:13 +05:30
|
|
|
__THROW __nonnull ((1)) __fortified_attr_access (__write_only__, 1, 2);
|
2017-01-06 11:05:27 -02:00
|
|
|
|
|
|
|
|
__fortify_function void
|
|
|
|
|
__NTH (explicit_bzero (void *__dest, size_t __len))
|
|
|
|
|
{
|
2020-12-30 11:09:58 +05:30
|
|
|
__explicit_bzero_chk (__dest, __len, __glibc_objsize0 (__dest));
|
2017-01-06 11:05:27 -02:00
|
|
|
}
|
2004-10-18 04:17:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
2012-04-29 15:34:20 +02:00
|
|
|
__fortify_function char *
|
2012-01-07 23:57:22 -05:00
|
|
|
__NTH (strcpy (char *__restrict __dest, const char *__restrict __src))
|
2007-09-15 02:38:04 +00:00
|
|
|
{
|
2020-12-30 11:09:58 +05:30
|
|
|
return __builtin___strcpy_chk (__dest, __src, __glibc_objsize (__dest));
|
2007-09-15 02:38:04 +00:00
|
|
|
}
|
2004-10-18 04:17:19 +00:00
|
|
|
|
2022-01-12 23:34:48 +05:30
|
|
|
#ifdef __USE_XOPEN2K8
|
2012-04-29 15:34:20 +02:00
|
|
|
__fortify_function char *
|
2012-01-07 23:57:22 -05:00
|
|
|
__NTH (stpcpy (char *__restrict __dest, const char *__restrict __src))
|
2007-09-15 02:38:04 +00:00
|
|
|
{
|
2020-12-30 11:09:58 +05:30
|
|
|
return __builtin___stpcpy_chk (__dest, __src, __glibc_objsize (__dest));
|
2007-09-15 02:38:04 +00:00
|
|
|
}
|
2004-10-18 04:17:19 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
2012-04-29 15:34:20 +02:00
|
|
|
__fortify_function char *
|
2012-01-07 23:57:22 -05:00
|
|
|
__NTH (strncpy (char *__restrict __dest, const char *__restrict __src,
|
2007-09-15 02:38:04 +00:00
|
|
|
size_t __len))
|
|
|
|
|
{
|
2020-12-30 11:09:58 +05:30
|
|
|
return __builtin___strncpy_chk (__dest, __src, __len,
|
|
|
|
|
__glibc_objsize (__dest));
|
2007-09-15 02:38:04 +00:00
|
|
|
}
|
2004-10-18 04:17:19 +00:00
|
|
|
|
2022-01-12 23:34:48 +05:30
|
|
|
#ifdef __USE_XOPEN2K8
|
|
|
|
|
# if __GNUC_PREREQ (4, 7) || __glibc_clang_prereq (2, 6)
|
2020-11-12 12:09:56 +05:30
|
|
|
__fortify_function char *
|
|
|
|
|
__NTH (stpncpy (char *__dest, const char *__src, size_t __n))
|
|
|
|
|
{
|
2020-12-30 11:09:58 +05:30
|
|
|
return __builtin___stpncpy_chk (__dest, __src, __n,
|
|
|
|
|
__glibc_objsize (__dest));
|
2020-11-12 12:09:56 +05:30
|
|
|
}
|
2022-01-12 23:34:48 +05:30
|
|
|
# else
|
2012-01-07 23:57:22 -05:00
|
|
|
extern char *__stpncpy_chk (char *__dest, const char *__src, size_t __n,
|
2020-05-04 11:21:50 -06:00
|
|
|
size_t __destlen) __THROW
|
2022-05-23 13:56:43 +05:30
|
|
|
__fortified_attr_access (__write_only__, 1, 3)
|
2021-10-12 12:29:13 +05:30
|
|
|
__attr_access ((__read_only__, 2));
|
2012-01-07 23:57:22 -05:00
|
|
|
extern char *__REDIRECT_NTH (__stpncpy_alias, (char *__dest, const char *__src,
|
2005-08-08 19:04:11 +00:00
|
|
|
size_t __n), stpncpy);
|
2005-07-15 10:32:45 +00:00
|
|
|
|
2012-04-29 15:34:20 +02:00
|
|
|
__fortify_function char *
|
2012-01-07 23:57:22 -05:00
|
|
|
__NTH (stpncpy (char *__dest, const char *__src, size_t __n))
|
2005-07-15 10:32:45 +00:00
|
|
|
{
|
|
|
|
|
if (__bos (__dest) != (size_t) -1
|
2015-08-14 09:21:44 -04:00
|
|
|
&& (!__builtin_constant_p (__n) || __n > __bos (__dest)))
|
2005-07-15 10:32:45 +00:00
|
|
|
return __stpncpy_chk (__dest, __src, __n, __bos (__dest));
|
|
|
|
|
return __stpncpy_alias (__dest, __src, __n);
|
|
|
|
|
}
|
2022-01-12 23:34:48 +05:30
|
|
|
# endif
|
2020-11-12 12:09:56 +05:30
|
|
|
#endif
|
2005-07-15 10:32:45 +00:00
|
|
|
|
|
|
|
|
|
2012-04-29 15:34:20 +02:00
|
|
|
__fortify_function char *
|
2012-01-07 23:57:22 -05:00
|
|
|
__NTH (strcat (char *__restrict __dest, const char *__restrict __src))
|
2007-09-15 02:38:04 +00:00
|
|
|
{
|
2020-12-30 11:09:58 +05:30
|
|
|
return __builtin___strcat_chk (__dest, __src, __glibc_objsize (__dest));
|
2007-09-15 02:38:04 +00:00
|
|
|
}
|
2004-10-18 04:17:19 +00:00
|
|
|
|
|
|
|
|
|
2012-04-29 15:34:20 +02:00
|
|
|
__fortify_function char *
|
2012-01-07 23:57:22 -05:00
|
|
|
__NTH (strncat (char *__restrict __dest, const char *__restrict __src,
|
2007-09-15 02:38:04 +00:00
|
|
|
size_t __len))
|
|
|
|
|
{
|
2020-12-30 11:09:58 +05:30
|
|
|
return __builtin___strncat_chk (__dest, __src, __len,
|
|
|
|
|
__glibc_objsize (__dest));
|
2007-09-15 02:38:04 +00:00
|
|
|
}
|
2016-11-17 09:26:27 -05:00
|
|
|
|
|
|
|
|
#endif /* bits/string_fortified.h */
|