memcpy-chk.c 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /* Checking memcpy.
  2. Copyright (C) 2005-2022 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify it under
  5. the terms of the GNU General Public License as published by the Free
  6. Software Foundation; either version 3, or (at your option) any later
  7. version.
  8. In addition to the permissions in the GNU General Public License, the
  9. Free Software Foundation gives you unlimited permission to link the
  10. compiled version of this file into combinations with other programs,
  11. and to distribute those combinations without any restriction coming
  12. from the use of this file. (The General Public License restrictions
  13. do apply in other respects; for example, they cover modification of
  14. the file, and distribution when not linked into a combine
  15. executable.)
  16. GCC is distributed in the hope that it will be useful, but WITHOUT ANY
  17. WARRANTY; without even the implied warranty of MERCHANTABILITY or
  18. FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
  19. for more details.
  20. Under Section 7 of GPL version 3, you are granted additional
  21. permissions described in the GCC Runtime Library Exception, version
  22. 3.1, as published by the Free Software Foundation.
  23. You should have received a copy of the GNU General Public License and
  24. a copy of the GCC Runtime Library Exception along with this program;
  25. see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
  26. <http://www.gnu.org/licenses/>. */
  27. #include "config.h"
  28. #include <ssp/ssp.h>
  29. #ifdef HAVE_STRING_H
  30. # include <string.h>
  31. #endif
  32. extern void __chk_fail (void) __attribute__((__noreturn__));
  33. void *
  34. __memcpy_chk (void *__restrict__ dest, const void *__restrict__ src,
  35. size_t len, size_t slen)
  36. {
  37. if (len > slen)
  38. __chk_fail ();
  39. return memcpy (dest, src, len);
  40. }