14fee23f9Smrg /* Checking strcpy.
2*b1e83836Smrg Copyright (C) 2005-2022 Free Software Foundation, Inc.
34fee23f9Smrg
44fee23f9Smrg This file is part of GCC.
54fee23f9Smrg
64fee23f9Smrg GCC is free software; you can redistribute it and/or modify it under
74fee23f9Smrg the terms of the GNU General Public License as published by the Free
84fee23f9Smrg Software Foundation; either version 3, or (at your option) any later
94fee23f9Smrg version.
104fee23f9Smrg
114fee23f9Smrg In addition to the permissions in the GNU General Public License, the
124fee23f9Smrg Free Software Foundation gives you unlimited permission to link the
134fee23f9Smrg compiled version of this file into combinations with other programs,
144fee23f9Smrg and to distribute those combinations without any restriction coming
154fee23f9Smrg from the use of this file. (The General Public License restrictions
164fee23f9Smrg do apply in other respects; for example, they cover modification of
174fee23f9Smrg the file, and distribution when not linked into a combine
184fee23f9Smrg executable.)
194fee23f9Smrg
204fee23f9Smrg GCC is distributed in the hope that it will be useful, but WITHOUT ANY
214fee23f9Smrg WARRANTY; without even the implied warranty of MERCHANTABILITY or
224fee23f9Smrg FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
234fee23f9Smrg for more details.
244fee23f9Smrg
254fee23f9Smrg Under Section 7 of GPL version 3, you are granted additional
264fee23f9Smrg permissions described in the GCC Runtime Library Exception, version
274fee23f9Smrg 3.1, as published by the Free Software Foundation.
284fee23f9Smrg
294fee23f9Smrg You should have received a copy of the GNU General Public License and
304fee23f9Smrg a copy of the GCC Runtime Library Exception along with this program;
314fee23f9Smrg see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
324fee23f9Smrg <http://www.gnu.org/licenses/>. */
334fee23f9Smrg
344fee23f9Smrg
354fee23f9Smrg #include "config.h"
364fee23f9Smrg #include <ssp/ssp.h>
374fee23f9Smrg #ifdef HAVE_STRING_H
384fee23f9Smrg # include <string.h>
394fee23f9Smrg #endif
404fee23f9Smrg
414fee23f9Smrg extern void __chk_fail (void) __attribute__((__noreturn__));
424fee23f9Smrg
434fee23f9Smrg char *
__strcpy_chk(char * __restrict__ dest,const char * __restrict__ src,size_t slen)444fee23f9Smrg __strcpy_chk (char *__restrict__ dest, const char *__restrict__ src,
454fee23f9Smrg size_t slen)
464fee23f9Smrg {
474fee23f9Smrg size_t len = strlen (src);
484fee23f9Smrg if (len >= slen)
494fee23f9Smrg __chk_fail ();
504fee23f9Smrg return memcpy (dest, src, len + 1);
514fee23f9Smrg }
52