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