Blame string/bits/string_fortified.h

Packit 6c4009
/* Copyright (C) 2004-2018 Free Software Foundation, Inc.
Packit 6c4009
   This file is part of the GNU C Library.
Packit 6c4009
Packit 6c4009
   The GNU C Library is free software; you can redistribute it and/or
Packit 6c4009
   modify it under the terms of the GNU Lesser General Public
Packit 6c4009
   License as published by the Free Software Foundation; either
Packit 6c4009
   version 2.1 of the License, or (at your option) any later version.
Packit 6c4009
Packit 6c4009
   The GNU C Library is distributed in the hope that it will be useful,
Packit 6c4009
   but WITHOUT ANY WARRANTY; without even the implied warranty of
Packit 6c4009
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Packit 6c4009
   Lesser General Public License for more details.
Packit 6c4009
Packit 6c4009
   You should have received a copy of the GNU Lesser General Public
Packit 6c4009
   License along with the GNU C Library; if not, see
Packit 6c4009
   <http://www.gnu.org/licenses/>.  */
Packit 6c4009
Packit 6c4009
#ifndef _BITS_STRING_FORTIFIED_H
Packit 6c4009
#define _BITS_STRING_FORTIFIED_H 1
Packit 6c4009
Packit 6c4009
#ifndef _STRING_H
Packit 6c4009
# error "Never use <bits/string_fortified.h> directly; include <string.h> instead."
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
#if !__GNUC_PREREQ (5,0)
Packit 6c4009
__warndecl (__warn_memset_zero_len,
Packit 6c4009
	    "memset used with constant zero length parameter; this could be due to transposed parameters");
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
__fortify_function void *
Packit 6c4009
__NTH (memcpy (void *__restrict __dest, const void *__restrict __src,
Packit 6c4009
	       size_t __len))
Packit 6c4009
{
Packit 6c4009
  return __builtin___memcpy_chk (__dest, __src, __len, __bos0 (__dest));
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
__fortify_function void *
Packit 6c4009
__NTH (memmove (void *__dest, const void *__src, size_t __len))
Packit 6c4009
{
Packit 6c4009
  return __builtin___memmove_chk (__dest, __src, __len, __bos0 (__dest));
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#ifdef __USE_GNU
Packit 6c4009
__fortify_function void *
Packit 6c4009
__NTH (mempcpy (void *__restrict __dest, const void *__restrict __src,
Packit 6c4009
		size_t __len))
Packit 6c4009
{
Packit 6c4009
  return __builtin___mempcpy_chk (__dest, __src, __len, __bos0 (__dest));
Packit 6c4009
}
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
Packit 6c4009
/* The first two tests here help to catch a somewhat common problem
Packit 6c4009
   where the second and third parameter are transposed.  This is
Packit 6c4009
   especially problematic if the intended fill value is zero.  In this
Packit 6c4009
   case no work is done at all.  We detect these problems by referring
Packit 6c4009
   non-existing functions.  */
Packit 6c4009
__fortify_function void *
Packit 6c4009
__NTH (memset (void *__dest, int __ch, size_t __len))
Packit 6c4009
{
Packit 6c4009
  /* GCC-5.0 and newer implements these checks in the compiler, so we don't
Packit 6c4009
     need them here.  */
Packit 6c4009
#if !__GNUC_PREREQ (5,0)
Packit 6c4009
  if (__builtin_constant_p (__len) && __len == 0
Packit 6c4009
      && (!__builtin_constant_p (__ch) || __ch != 0))
Packit 6c4009
    {
Packit 6c4009
      __warn_memset_zero_len ();
Packit 6c4009
      return __dest;
Packit 6c4009
    }
Packit 6c4009
#endif
Packit 6c4009
  return __builtin___memset_chk (__dest, __ch, __len, __bos0 (__dest));
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#ifdef __USE_MISC
Packit 6c4009
# include <bits/strings_fortified.h>
Packit 6c4009
Packit 6c4009
void __explicit_bzero_chk (void *__dest, size_t __len, size_t __destlen)
Packit 6c4009
  __THROW __nonnull ((1));
Packit 6c4009
Packit 6c4009
__fortify_function void
Packit 6c4009
__NTH (explicit_bzero (void *__dest, size_t __len))
Packit 6c4009
{
Packit 6c4009
  __explicit_bzero_chk (__dest, __len, __bos0 (__dest));
Packit 6c4009
}
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
__fortify_function char *
Packit 6c4009
__NTH (strcpy (char *__restrict __dest, const char *__restrict __src))
Packit 6c4009
{
Packit 6c4009
  return __builtin___strcpy_chk (__dest, __src, __bos (__dest));
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#ifdef __USE_GNU
Packit 6c4009
__fortify_function char *
Packit 6c4009
__NTH (stpcpy (char *__restrict __dest, const char *__restrict __src))
Packit 6c4009
{
Packit 6c4009
  return __builtin___stpcpy_chk (__dest, __src, __bos (__dest));
Packit 6c4009
}
Packit 6c4009
#endif
Packit 6c4009
Packit 6c4009
Packit 6c4009
__fortify_function char *
Packit 6c4009
__NTH (strncpy (char *__restrict __dest, const char *__restrict __src,
Packit 6c4009
		size_t __len))
Packit 6c4009
{
Packit 6c4009
  return __builtin___strncpy_chk (__dest, __src, __len, __bos (__dest));
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
/* XXX We have no corresponding builtin yet.  */
Packit 6c4009
extern char *__stpncpy_chk (char *__dest, const char *__src, size_t __n,
Packit 6c4009
			    size_t __destlen) __THROW;
Packit 6c4009
extern char *__REDIRECT_NTH (__stpncpy_alias, (char *__dest, const char *__src,
Packit 6c4009
					       size_t __n), stpncpy);
Packit 6c4009
Packit 6c4009
__fortify_function char *
Packit 6c4009
__NTH (stpncpy (char *__dest, const char *__src, size_t __n))
Packit 6c4009
{
Packit 6c4009
  if (__bos (__dest) != (size_t) -1
Packit 6c4009
      && (!__builtin_constant_p (__n) || __n > __bos (__dest)))
Packit 6c4009
    return __stpncpy_chk (__dest, __src, __n, __bos (__dest));
Packit 6c4009
  return __stpncpy_alias (__dest, __src, __n);
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
Packit 6c4009
__fortify_function char *
Packit 6c4009
__NTH (strcat (char *__restrict __dest, const char *__restrict __src))
Packit 6c4009
{
Packit 6c4009
  return __builtin___strcat_chk (__dest, __src, __bos (__dest));
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
Packit 6c4009
__fortify_function char *
Packit 6c4009
__NTH (strncat (char *__restrict __dest, const char *__restrict __src,
Packit 6c4009
		size_t __len))
Packit 6c4009
{
Packit 6c4009
  return __builtin___strncat_chk (__dest, __src, __len, __bos (__dest));
Packit 6c4009
}
Packit 6c4009
Packit 6c4009
#endif /* bits/string_fortified.h */