Home | History | Annotate | Line # | Download | only in libssp
strcat-chk.c revision 1.1.1.1.8.2
      1  1.1.1.1.8.2  tls /* Checking strcat.
      2  1.1.1.1.8.2  tls    Copyright (C) 1991, 1997, 2003, 2004, 2005, 2009 Free Software Foundation, Inc.
      3  1.1.1.1.8.2  tls 
      4  1.1.1.1.8.2  tls This file is part of GCC.
      5  1.1.1.1.8.2  tls 
      6  1.1.1.1.8.2  tls GCC is free software; you can redistribute it and/or modify it under
      7  1.1.1.1.8.2  tls the terms of the GNU General Public License as published by the Free
      8  1.1.1.1.8.2  tls Software Foundation; either version 3, or (at your option) any later
      9  1.1.1.1.8.2  tls version.
     10  1.1.1.1.8.2  tls 
     11  1.1.1.1.8.2  tls In addition to the permissions in the GNU General Public License, the
     12  1.1.1.1.8.2  tls Free Software Foundation gives you unlimited permission to link the
     13  1.1.1.1.8.2  tls compiled version of this file into combinations with other programs,
     14  1.1.1.1.8.2  tls and to distribute those combinations without any restriction coming
     15  1.1.1.1.8.2  tls from the use of this file.  (The General Public License restrictions
     16  1.1.1.1.8.2  tls do apply in other respects; for example, they cover modification of
     17  1.1.1.1.8.2  tls the file, and distribution when not linked into a combine
     18  1.1.1.1.8.2  tls executable.)
     19  1.1.1.1.8.2  tls 
     20  1.1.1.1.8.2  tls GCC is distributed in the hope that it will be useful, but WITHOUT ANY
     21  1.1.1.1.8.2  tls WARRANTY; without even the implied warranty of MERCHANTABILITY or
     22  1.1.1.1.8.2  tls FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
     23  1.1.1.1.8.2  tls for more details.
     24  1.1.1.1.8.2  tls 
     25  1.1.1.1.8.2  tls Under Section 7 of GPL version 3, you are granted additional
     26  1.1.1.1.8.2  tls permissions described in the GCC Runtime Library Exception, version
     27  1.1.1.1.8.2  tls 3.1, as published by the Free Software Foundation.
     28  1.1.1.1.8.2  tls 
     29  1.1.1.1.8.2  tls You should have received a copy of the GNU General Public License and
     30  1.1.1.1.8.2  tls a copy of the GCC Runtime Library Exception along with this program;
     31  1.1.1.1.8.2  tls see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
     32  1.1.1.1.8.2  tls <http://www.gnu.org/licenses/>.  */
     33  1.1.1.1.8.2  tls 
     34  1.1.1.1.8.2  tls 
     35  1.1.1.1.8.2  tls #include "config.h"
     36  1.1.1.1.8.2  tls #include <ssp/ssp.h>
     37  1.1.1.1.8.2  tls #ifdef HAVE_STRING_H
     38  1.1.1.1.8.2  tls # include <string.h>
     39  1.1.1.1.8.2  tls #endif
     40  1.1.1.1.8.2  tls 
     41  1.1.1.1.8.2  tls extern void __chk_fail (void) __attribute__((__noreturn__));
     42  1.1.1.1.8.2  tls 
     43  1.1.1.1.8.2  tls char *
     44  1.1.1.1.8.2  tls __strcat_chk (char *__restrict__ dest, const char *__restrict__ src,
     45  1.1.1.1.8.2  tls               size_t slen)
     46  1.1.1.1.8.2  tls {
     47  1.1.1.1.8.2  tls   char *s1 = dest;
     48  1.1.1.1.8.2  tls   const char *s2 = src;
     49  1.1.1.1.8.2  tls   char c;
     50  1.1.1.1.8.2  tls 
     51  1.1.1.1.8.2  tls   do
     52  1.1.1.1.8.2  tls     {
     53  1.1.1.1.8.2  tls       if (slen-- == 0)
     54  1.1.1.1.8.2  tls         __chk_fail ();
     55  1.1.1.1.8.2  tls       c = *s1++;
     56  1.1.1.1.8.2  tls     }
     57  1.1.1.1.8.2  tls   while (c != '\0');
     58  1.1.1.1.8.2  tls 
     59  1.1.1.1.8.2  tls   ++slen;
     60  1.1.1.1.8.2  tls   s1 -= 2;
     61  1.1.1.1.8.2  tls 
     62  1.1.1.1.8.2  tls   do
     63  1.1.1.1.8.2  tls     {
     64  1.1.1.1.8.2  tls       if (slen-- == 0)
     65  1.1.1.1.8.2  tls         __chk_fail ();
     66  1.1.1.1.8.2  tls       c = *s2++;
     67  1.1.1.1.8.2  tls       *++s1 = c;
     68  1.1.1.1.8.2  tls     }
     69  1.1.1.1.8.2  tls   while (c != '\0');
     70  1.1.1.1.8.2  tls 
     71  1.1.1.1.8.2  tls   return dest;
     72  1.1.1.1.8.2  tls }
     73