--- /dev/null
+/* Checking gets.
+ Copyright (C) 2005, 2009 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. */
+
+
+#include "config.h"
+#include <ssp/ssp.h>
+#include <stdarg.h>
+#ifdef HAVE_STDLIB_H
+# include <stdlib.h>
+#endif
+#ifdef HAVE_ALLOCA_H
+# include <alloca.h>
+#endif
+#ifdef HAVE_LIMITS_H
+# include <limits.h>
+#endif
+#ifdef HAVE_STDIO_H
+# include <stdio.h>
+#endif
+#ifdef HAVE_STRING_H
+# include <string.h>
+#endif
+
+extern void __chk_fail (void) __attribute__((__noreturn__));
+
+char *
+__gets_chk (char *s, size_t slen)
+{
+ char *ret, *buf;
+
+ if (slen >= (size_t) INT_MAX)
+ return gets (s);
+
+ if (slen <= 8192)
+ buf = alloca (slen + 1);
+ else
+ buf = malloc (slen + 1);
+ if (buf == NULL)
+ return gets (s);
+
+ ret = fgets (buf, (int) (slen + 1), stdin);
+ if (ret != NULL)
+ {
+ size_t len = strlen (buf);
+ if (len > 0 && buf[len - 1] == '\n')
+ --len;
+ if (len == slen)
+ __chk_fail ();
+ memcpy (s, buf, len);
+ s[len] = '\0';
+ ret = s;
+ }
+
+ if (slen > 8192)
+ free (buf);
+ return ret;
+}
--- /dev/null
+/* Checking memcpy.
+ Copyright (C) 2005, 2009 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. */
+
+
+#include "config.h"
+#include <ssp/ssp.h>
+#ifdef HAVE_STRING_H
+# include <string.h>
+#endif
+
+extern void __chk_fail (void) __attribute__((__noreturn__));
+
+void *
+__memcpy_chk (void *__restrict__ dest, const void *__restrict__ src,
+ size_t len, size_t slen)
+{
+ if (len > slen)
+ __chk_fail ();
+ return memcpy (dest, src, len);
+}
--- /dev/null
+/* Checking memmove.
+ Copyright (C) 2005, 2009, 2010 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. */
+
+
+#include "config.h"
+#include <ssp/ssp.h>
+#ifdef HAVE_STRING_H
+# include <string.h>
+#endif
+
+extern void __chk_fail (void) __attribute__((__noreturn__));
+
+#ifdef HAVE_MEMMOVE
+void *
+__memmove_chk (void *dest, const void *src, size_t len, size_t slen)
+{
+ if (len > slen)
+ __chk_fail ();
+ return memmove (dest, src, len);
+}
+#endif
--- /dev/null
+/* Checking mempcpy.
+ Copyright (C) 2005, 2009 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. */
+
+
+#include "config.h"
+#include <ssp/ssp.h>
+#ifdef HAVE_STRING_H
+# include <string.h>
+#endif
+
+extern void __chk_fail (void) __attribute__((__noreturn__));
+
+#ifdef HAVE_MEMPCPY
+void *
+__mempcpy_chk (void *__restrict__ dest, const void *__restrict__ src,
+ size_t len, size_t slen)
+{
+ if (len > slen)
+ __chk_fail ();
+ return memcpy (dest, src, len) + len;
+}
+#endif
--- /dev/null
+/* Checking memset.
+ Copyright (C) 2005, 2009 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. */
+
+
+#include "config.h"
+#include <ssp/ssp.h>
+#ifdef HAVE_STRING_H
+# include <string.h>
+#endif
+
+extern void __chk_fail (void) __attribute__((__noreturn__));
+
+void *
+__memset_chk (void *dest, int val, size_t len, size_t slen)
+{
+ if (len > slen)
+ __chk_fail ();
+ return memset (dest, val, len);
+}
--- /dev/null
+/* Checking snprintf.
+ Copyright (C) 2005, 2009 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. */
+
+
+#include "config.h"
+#include <ssp/ssp.h>
+#include <stdarg.h>
+#ifdef HAVE_STDIO_H
+# include <stdio.h>
+#endif
+
+extern void __chk_fail (void) __attribute__((__noreturn__));
+
+#ifdef HAVE_USABLE_VSNPRINTF
+int
+__snprintf_chk (char *s, size_t n, int flags __attribute__((unused)),
+ size_t slen, const char *format, ...)
+{
+ va_list arg;
+ int done;
+
+ if (n > slen)
+ __chk_fail ();
+
+ va_start (arg, format);
+ done = vsnprintf (s, n, format, arg);
+ va_end (arg);
+
+ return done;
+}
+#endif
--- /dev/null
+/* Checking sprintf.
+ Copyright (C) 2005, 2009 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. */
+
+
+#include "config.h"
+#include <ssp/ssp.h>
+#include <stdarg.h>
+#ifdef HAVE_LIMITS_H
+# include <limits.h>
+#endif
+#ifdef HAVE_STDIO_H
+# include <stdio.h>
+#endif
+
+extern void __chk_fail (void) __attribute__((__noreturn__));
+
+#ifdef HAVE_USABLE_VSNPRINTF
+int
+__sprintf_chk (char *s, int flags __attribute__((unused)),
+ size_t slen, const char *format, ...)
+{
+ va_list arg;
+ int done;
+
+ va_start (arg, format);
+ if (slen > (size_t) INT_MAX)
+ done = vsprintf (s, format, arg);
+ else
+ {
+ done = vsnprintf (s, slen, format, arg);
+ if (done >= 0 && (size_t) done >= slen)
+ __chk_fail ();
+ }
+ va_end (arg);
+ return done;
+}
+#endif
--- /dev/null
+/* Stack protector support.
+ Copyright (C) 2005, 2009 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. */
+
+
+#include "config.h"
+
+extern void __stack_chk_fail (void);
+
+/* Some targets can avoid loading a GP for calls to hidden functions.
+ Using this entry point may avoid the load of a GP entirely for the
+ function, making the overall code smaller. */
+
+#ifdef HAVE_HIDDEN_VISIBILITY
+void
+__attribute__((visibility ("hidden")))
+__stack_chk_fail_local (void)
+{
+ __stack_chk_fail ();
+}
+#endif
--- /dev/null
+/* Stack protector support.
+ Copyright (C) 2005, 2009 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. */
+
+
+#include "config.h"
+#ifdef HAVE_ALLOCA_H
+# include <alloca.h>
+#endif
+#ifdef HAVE_MALLOC_H
+# include <malloc.h>
+#endif
+#ifdef HAVE_STRING_H
+# include <string.h>
+#endif
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+#ifdef HAVE_FCNTL_H
+# include <fcntl.h>
+#endif
+#ifdef HAVE_PATHS_H
+# include <paths.h>
+#endif
+#ifndef _PATH_TTY
+/* Native win32 apps don't know about /dev/tty but can print directly
+ to the console using "CONOUT$" */
+#if defined (_WIN32) && !defined (__CYGWIN__)
+# define _PATH_TTY "CONOUT$"
+#else
+# define _PATH_TTY "/dev/tty"
+#endif
+#endif
+#ifdef HAVE_SYSLOG_H
+# include <syslog.h>
+#endif
+
+void *__stack_chk_guard = 0;
+
+static void __attribute__ ((constructor))
+__guard_setup (void)
+{
+ unsigned char *p;
+ int fd;
+
+ if (__stack_chk_guard != 0)
+ return;
+
+ fd = open ("/dev/urandom", O_RDONLY);
+ if (fd != -1)
+ {
+ ssize_t size = read (fd, &__stack_chk_guard,
+ sizeof (__stack_chk_guard));
+ close (fd);
+ if (size == sizeof(__stack_chk_guard) && __stack_chk_guard != 0)
+ return;
+ }
+
+ /* If a random generator can't be used, the protector switches the guard
+ to the "terminator canary". */
+ p = (unsigned char *) &__stack_chk_guard;
+ p[sizeof(__stack_chk_guard)-1] = 255;
+ p[sizeof(__stack_chk_guard)-2] = '\n';
+ p[0] = 0;
+}
+
+static void
+fail (const char *msg1, size_t msg1len, const char *msg3)
+{
+#ifdef __GNU_LIBRARY__
+ extern char * __progname;
+#else
+ static const char __progname[] = "";
+#endif
+ int fd;
+
+ /* Print error message directly to the tty. This avoids Bad Things
+ happening if stderr is redirected. */
+ fd = open (_PATH_TTY, O_WRONLY);
+ if (fd != -1)
+ {
+ static const char msg2[] = " terminated\n";
+ size_t progname_len, len;
+ char *buf, *p;
+
+ progname_len = strlen (__progname);
+ len = msg1len + progname_len + sizeof(msg2)-1 + 1;
+ p = buf = alloca (len);
+
+ memcpy (p, msg1, msg1len);
+ p += msg1len;
+ memcpy (p, __progname, progname_len);
+ p += progname_len;
+ memcpy (p, msg2, sizeof(msg2));
+
+ while (len > 0)
+ {
+ ssize_t wrote = write (fd, buf, len);
+ if (wrote < 0)
+ break;
+ buf += wrote;
+ len -= wrote;
+ }
+ close (fd);
+ }
+
+#ifdef HAVE_SYSLOG_H
+ /* Only send the error to syslog if there was no tty available. */
+ else
+ syslog (LOG_CRIT, msg3);
+#endif /* HAVE_SYSLOG_H */
+
+ /* Try very hard to exit. Note that signals may be blocked preventing
+ the first two options from working. The use of volatile is here to
+ prevent optimizers from "knowing" that __builtin_trap is called first,
+ and that it doesn't return, and so "obviously" the rest of the code
+ is dead. */
+ {
+ volatile int state;
+ for (state = 0; ; state++)
+ switch (state)
+ {
+ case 0:
+ __builtin_trap ();
+ break;
+ case 1:
+ *(volatile int *)-1L = 0;
+ break;
+ case 2:
+ _exit (127);
+ break;
+ }
+ }
+}
+
+void
+__stack_chk_fail (void)
+{
+ const char *msg = "*** stack smashing detected ***: ";
+ fail (msg, strlen (msg), "stack smashing detected: terminated");
+}
+
+void
+__chk_fail (void)
+{
+ const char *msg = "*** buffer overflow detected ***: ";
+ fail (msg, strlen (msg), "buffer overflow detected: terminated");
+}
+
+#ifdef HAVE_HIDDEN_VISIBILITY
+void
+__attribute__((visibility ("hidden")))
+__stack_chk_fail_local (void)
+{
+ __stack_chk_fail ();
+}
+#endif
--- /dev/null
+LIBSSP_1.0 {
+ global:
+ __stack_chk_fail;
+ __stack_chk_guard;
+ __chk_fail;
+ __gets_chk;
+ __memcpy_chk;
+ __memmove_chk;
+ __mempcpy_chk;
+ __memset_chk;
+ __snprintf_chk;
+ __sprintf_chk;
+ __stpcpy_chk;
+ __strcat_chk;
+ __strcpy_chk;
+ __strncat_chk;
+ __strncpy_chk;
+ __vsnprintf_chk;
+ __vsprintf_chk;
+ local:
+ *;
+};
--- /dev/null
+/* Object size checking support macros.
+ Copyright (C) 2004, 2005, 2009 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. */
+
+
+#ifndef _SSP_H
+#define _SSP_H 1
+
+#if _FORTIFY_SOURCE > 0 && __OPTIMIZE__ > 0 \
+ && defined __GNUC__ \
+ && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 1)) \
+ && !defined __cplusplus
+# if _FORTIFY_SOURCE == 1
+# define __SSP_FORTIFY_LEVEL 1
+# elif _FORTIFY_SOURCE > 1
+# define __SSP_FORTIFY_LEVEL 2
+# endif
+#endif
+
+#if __SSP_FORTIFY_LEVEL > 0
+# include <stddef.h>
+# define __ssp_bos(ptr) __builtin_object_size (ptr, __SSP_FORTIFY_LEVEL > 1)
+# define __ssp_bos0(ptr) __builtin_object_size (ptr, 0)
+
+# define __SSP_REDIRECT(name, proto, alias) \
+ name proto __asm__ (__SSP_ASMNAME (#alias))
+# define __SSP_ASMNAME(cname) __SSP_ASMNAME2 (__USER_LABEL_PREFIX__, cname)
+# define __SSP_ASMNAME2(prefix, cname) __SSP_ASMNAME3 (prefix) cname
+# define __SSP_ASMNAME3(prefix) #prefix
+
+# @ssp_have_usable_vsnprintf@ __SSP_HAVE_VSNPRINTF
+
+extern void __chk_fail (void) __attribute__((__noreturn__));
+#endif
+
+#endif /* _SSP_H */
--- /dev/null
+/* Checking macros for stdio functions.
+ Copyright (C) 2004, 2005, 2009 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. */
+
+
+#ifndef _SSP_STDIO_H
+#define _SSP_STDIO_H 1
+
+#include <ssp.h>
+#include_next <stdio.h>
+
+#if __SSP_FORTIFY_LEVEL > 0
+
+#include <stdarg.h>
+
+#undef sprintf
+#undef vsprintf
+#undef snprintf
+#undef vsnprintf
+#undef gets
+#undef fgets
+
+extern int __sprintf_chk (char *__restrict__ __s, int __flag, size_t __slen,
+ __const char *__restrict__ __format, ...);
+extern int __vsprintf_chk (char *__restrict__ __s, int __flag, size_t __slen,
+ __const char *__restrict__ __format,
+ va_list __ap);
+
+#define sprintf(str, ...) \
+ __builtin___sprintf_chk (str, 0, __ssp_bos (str), \
+ __VA_ARGS__)
+#define vsprintf(str, fmt, ap) \
+ __builtin___vsprintf_chk (str, 0, __ssp_bos (str), fmt, ap)
+
+extern int __snprintf_chk (char *__restrict__ __s, size_t __n, int __flag,
+ size_t __slen, __const char *__restrict__ __format,
+ ...);
+extern int __vsnprintf_chk (char *__restrict__ __s, size_t __n, int __flag,
+ size_t __slen, __const char *__restrict__ __format,
+ va_list __ap);
+
+#define snprintf(str, len, ...) \
+ __builtin___snprintf_chk (str, len, 0, __ssp_bos (str), __VA_ARGS__)
+#define vsnprintf(str, len, fmt, ap) \
+ __builtin___vsnprintf_chk (str, len, 0, __ssp_bos (str), fmt, ap)
+
+extern char *__gets_chk (char *__str, size_t);
+extern char *__SSP_REDIRECT (__gets_alias, (char *__str), gets);
+
+extern inline __attribute__((__always_inline__)) char *
+gets (char *__str)
+{
+ if (__ssp_bos (__str) != (size_t) -1)
+ return __gets_chk (__str, __ssp_bos (__str));
+ return __gets_alias (__str);
+}
+
+extern char *__SSP_REDIRECT (__fgets_alias,
+ (char *__restrict__ __s, int __n,
+ FILE *__restrict__ __stream), fgets);
+
+extern inline __attribute__((__always_inline__)) char *
+fgets (char *__restrict__ __s, int __n, FILE *__restrict__ __stream)
+{
+ if (__ssp_bos (__s) != (size_t) -1 && (size_t) __n > __ssp_bos (__s))
+ __chk_fail ();
+ return __fgets_alias (__s, __n, __stream);
+}
+
+#endif /* __SSP_FORTIFY_LEVEL > 0 */
+#endif /* _SSP_STDIO_H */
--- /dev/null
+/* Checking macros for string functions.
+ Copyright (C) 2004, 2005, 2009 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. */
+
+
+#ifndef _SSP_STRING_H
+#define _SSP_STRING_H 1
+
+#include <ssp.h>
+#include_next <string.h>
+
+#if __SSP_FORTIFY_LEVEL > 0
+
+#undef memcpy
+#undef memmove
+#undef memset
+#undef strcat
+#undef strcpy
+#undef strncat
+#undef strncpy
+#undef mempcpy
+#undef stpcpy
+#undef bcopy
+#undef bzero
+
+#define memcpy(dest, src, len) \
+ ((__ssp_bos0 (dest) != (size_t) -1) \
+ ? __builtin___memcpy_chk (dest, src, len, __ssp_bos0 (dest)) \
+ : __memcpy_ichk (dest, src, len))
+static inline __attribute__((__always_inline__)) void *
+__memcpy_ichk (void *__restrict__ __dest, const void *__restrict__ __src,
+ size_t __len)
+{
+ return __builtin___memcpy_chk (__dest, __src, __len, __ssp_bos0 (__dest));
+}
+
+
+#define memmove(dest, src, len) \
+ ((__ssp_bos0 (dest) != (size_t) -1) \
+ ? __builtin___memmove_chk (dest, src, len, __ssp_bos0 (dest)) \
+ : __memmove_ichk (dest, src, len))
+static inline __attribute__((__always_inline__)) void *
+__memmove_ichk (void *__dest, const void *__src, size_t __len)
+{
+ return __builtin___memmove_chk (__dest, __src, __len, __ssp_bos0 (__dest));
+}
+
+
+#define mempcpy(dest, src, len) \
+ ((__ssp_bos0 (dest) != (size_t) -1) \
+ ? __builtin___mempcpy_chk (dest, src, len, __ssp_bos0 (dest)) \
+ : __mempcpy_ichk (dest, src, len))
+static inline __attribute__((__always_inline__)) void *
+__mempcpy_ichk (void *__restrict__ __dest, const void *__restrict__ __src,
+ size_t __len)
+{
+ return __builtin___mempcpy_chk (__dest, __src, __len, __ssp_bos0 (__dest));
+}
+
+
+#define memset(dest, ch, len) \
+ ((__ssp_bos0 (dest) != (size_t) -1) \
+ ? __builtin___memset_chk (dest, ch, len, __ssp_bos0 (dest)) \
+ : __memset_ichk (dest, ch, len))
+static inline __attribute__((__always_inline__)) void *
+__memset_ichk (void *__dest, int __ch, size_t __len)
+{
+ return __builtin___memset_chk (__dest, __ch, __len, __ssp_bos0 (__dest));
+}
+
+#define bcopy(src, dest, len) ((void) \
+ ((__ssp_bos0 (dest) != (size_t) -1) \
+ ? __builtin___memmove_chk (dest, src, len, __ssp_bos0 (dest)) \
+ : __memmove_ichk (dest, src, len)))
+#define bzero(dest, len) ((void) \
+ ((__ssp_bos0 (dest) != (size_t) -1) \
+ ? __builtin___memset_chk (dest, '\0', len, __ssp_bos0 (dest)) \
+ : __memset_ichk (dest, '\0', len)))
+
+
+#define strcpy(dest, src) \
+ ((__ssp_bos (dest) != (size_t) -1) \
+ ? __builtin___strcpy_chk (dest, src, __ssp_bos (dest)) \
+ : __strcpy_ichk (dest, src))
+static inline __attribute__((__always_inline__)) char *
+__strcpy_ichk (char *__restrict__ __dest, const char *__restrict__ __src)
+{
+ return __builtin___strcpy_chk (__dest, __src, __ssp_bos (__dest));
+}
+
+
+#define stpcpy(dest, src) \
+ ((__ssp_bos (dest) != (size_t) -1) \
+ ? __builtin___stpcpy_chk (dest, src, __ssp_bos (dest)) \
+ : __stpcpy_ichk (dest, src))
+static inline __attribute__((__always_inline__)) char *
+__stpcpy_ichk (char *__restrict__ __dest, const char *__restrict__ __src)
+{
+ return __builtin___stpcpy_chk (__dest, __src, __ssp_bos (__dest));
+}
+
+
+#define strncpy(dest, src, len) \
+ ((__ssp_bos (dest) != (size_t) -1) \
+ ? __builtin___strncpy_chk (dest, src, len, __ssp_bos (dest)) \
+ : __strncpy_ichk (dest, src, len))
+static inline __attribute__((__always_inline__)) char *
+__strncpy_ichk (char *__restrict__ __dest, const char *__restrict__ __src,
+ size_t __len)
+{
+ return __builtin___strncpy_chk (__dest, __src, __len, __ssp_bos (__dest));
+}
+
+
+#define strcat(dest, src) \
+ ((__ssp_bos (dest) != (size_t) -1) \
+ ? __builtin___strcat_chk (dest, src, __ssp_bos (dest)) \
+ : __strcat_ichk (dest, src))
+static inline __attribute__((__always_inline__)) char *
+__strcat_ichk (char *__restrict__ __dest, const char *__restrict__ __src)
+{
+ return __builtin___strcat_chk (__dest, __src, __ssp_bos (__dest));
+}
+
+
+#define strncat(dest, src, len) \
+ ((__ssp_bos (dest) != (size_t) -1) \
+ ? __builtin___strncat_chk (dest, src, len, __ssp_bos (dest)) \
+ : __strncat_ichk (dest, src, len))
+static inline __attribute__((__always_inline__)) char *
+__strncat_ichk (char *__restrict__ __dest, const char *__restrict__ __src,
+ size_t __len)
+{
+ return __builtin___strncat_chk (__dest, __src, __len, __ssp_bos (__dest));
+}
+
+#endif /* __SSP_FORTIFY_LEVEL > 0 */
+#endif /* _SSP_STRING_H */
--- /dev/null
+/* Checking macros for unistd functions.
+ Copyright (C) 2005, 2009 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. */
+
+
+#ifndef _SSP_UNISTD_H
+#define _SSP_UNISTD_H 1
+
+#include <ssp.h>
+#include_next <unistd.h>
+
+#if __SSP_FORTIFY_LEVEL > 0
+
+#undef read
+#undef readlink
+#undef getcwd
+
+extern ssize_t __SSP_REDIRECT (__read_alias, (int __fd, void *__buf,
+ size_t __nbytes), read);
+
+extern inline __attribute__((__always_inline__)) ssize_t
+read (int __fd, void *__buf, size_t __nbytes)
+{
+ if (__ssp_bos0 (__buf) != (size_t) -1 && __nbytes > __ssp_bos0 (__buf))
+ __chk_fail ();
+ return __read_alias (__fd, __buf, __nbytes);
+}
+
+extern int __SSP_REDIRECT (__readlink_alias,
+ (const char *__restrict__ __path,
+ char *__restrict__ __buf, size_t __len),
+ readlink);
+
+extern inline __attribute__((__always_inline__)) int
+readlink (const char *__restrict__ __path, char *__restrict__ __buf,
+ size_t __len)
+{
+ if (__ssp_bos (__buf) != (size_t) -1 && __len > __ssp_bos (__buf))
+ __chk_fail ();
+ return __readlink_alias (__path, __buf, __len);
+}
+
+extern char *__SSP_REDIRECT (__getcwd_alias,
+ (char *__buf, size_t __size), getcwd);
+
+extern inline __attribute__((__always_inline__)) char *
+getcwd (char *__buf, size_t __size)
+{
+ if (__ssp_bos (__buf) != (size_t) -1 && __size > __ssp_bos (__buf))
+ __chk_fail ();
+ return __getcwd_alias (__buf, __size);
+}
+
+#endif /* __SSP_FORTIFY_LEVEL > 0 */
+#endif /* _SSP_UNISTD_H */
--- /dev/null
+/* Checking stpcpy.
+ Copyright (C) 2005, 2009 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. */
+
+
+#include "config.h"
+#include <ssp/ssp.h>
+#ifdef HAVE_STRING_H
+# include <string.h>
+#endif
+
+extern void __chk_fail (void) __attribute__((__noreturn__));
+
+char *
+__stpcpy_chk (char *__restrict__ dest, const char *__restrict__ src,
+ size_t slen)
+{
+ size_t len = strlen (src);
+ if (len >= slen)
+ __chk_fail ();
+ return memcpy (dest, src, len + 1) + len;
+}
--- /dev/null
+/* Checking strcat.
+ Copyright (C) 1991, 1997, 2003, 2004, 2005, 2009 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. */
+
+
+#include "config.h"
+#include <ssp/ssp.h>
+#ifdef HAVE_STRING_H
+# include <string.h>
+#endif
+
+extern void __chk_fail (void) __attribute__((__noreturn__));
+
+char *
+__strcat_chk (char *__restrict__ dest, const char *__restrict__ src,
+ size_t slen)
+{
+ char *s1 = dest;
+ const char *s2 = src;
+ char c;
+
+ do
+ {
+ if (slen-- == 0)
+ __chk_fail ();
+ c = *s1++;
+ }
+ while (c != '\0');
+
+ ++slen;
+ s1 -= 2;
+
+ do
+ {
+ if (slen-- == 0)
+ __chk_fail ();
+ c = *s2++;
+ *++s1 = c;
+ }
+ while (c != '\0');
+
+ return dest;
+}
--- /dev/null
+/* Checking strcpy.
+ Copyright (C) 2005, 2009 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. */
+
+
+#include "config.h"
+#include <ssp/ssp.h>
+#ifdef HAVE_STRING_H
+# include <string.h>
+#endif
+
+extern void __chk_fail (void) __attribute__((__noreturn__));
+
+char *
+__strcpy_chk (char *__restrict__ dest, const char *__restrict__ src,
+ size_t slen)
+{
+ size_t len = strlen (src);
+ if (len >= slen)
+ __chk_fail ();
+ return memcpy (dest, src, len + 1);
+}
--- /dev/null
+/* Checking strncat.
+ Copyright (C) 1991, 1997, 2003, 2004, 2005, 2009 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. */
+
+
+#include "config.h"
+#include <ssp/ssp.h>
+#ifdef HAVE_STRING_H
+# include <string.h>
+#endif
+
+extern void __chk_fail (void) __attribute__((__noreturn__));
+
+char *
+__strncat_chk (char *__restrict__ dest, const char *__restrict__ src,
+ size_t n, size_t slen)
+{
+ char c;
+ char *s = dest;
+
+ do
+ {
+ if (slen-- == 0)
+ __chk_fail ();
+ c = *dest++;
+ }
+ while (c != '\0');
+
+ ++slen;
+ dest -= 2;
+
+ if (n >= 4)
+ {
+ size_t n4 = n >> 2;
+ do
+ {
+ if (slen-- == 0)
+ __chk_fail ();
+ c = *src++;
+ *++dest = c;
+ if (c == '\0')
+ return s;
+ if (slen-- == 0)
+ __chk_fail ();
+ c = *src++;
+ *++dest = c;
+ if (c == '\0')
+ return s;
+ if (slen-- == 0)
+ __chk_fail ();
+ c = *src++;
+ *++dest = c;
+ if (c == '\0')
+ return s;
+ if (slen-- == 0)
+ __chk_fail ();
+ c = *src++;
+ *++dest = c;
+ if (c == '\0')
+ return s;
+ if (slen-- == 0)
+ __chk_fail ();
+ c = *src++;
+ *++dest = c;
+ if (c == '\0')
+ return s;
+ } while (--n4 > 0);
+ n &= 3;
+ }
+
+ while (n > 0)
+ {
+ if (slen-- == 0)
+ __chk_fail ();
+ c = *src++;
+ *++dest = c;
+ if (c == '\0')
+ return s;
+ n--;
+ }
+
+ if (c != '\0')
+ {
+ if (slen-- == 0)
+ __chk_fail ();
+ *++dest = '\0';
+ }
+
+ return s;
+}
--- /dev/null
+/* Checking strncpy.
+ Copyright (C) 2005, 2009 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. */
+
+#include "config.h"
+#include <ssp/ssp.h>
+#ifdef HAVE_STRING_H
+# include <string.h>
+#endif
+
+extern void __chk_fail (void) __attribute__((__noreturn__));
+
+#ifdef HAVE_STRNCPY
+char *
+__strncpy_chk (char *__restrict__ dest, const char *__restrict__ src,
+ size_t len, size_t slen)
+{
+ if (len > slen)
+ __chk_fail ();
+ return strncpy (dest, src, len);
+}
+#endif
--- /dev/null
+/* Checking vsnprintf.
+ Copyright (C) 2005, 2009 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. */
+
+#include "config.h"
+#include <ssp/ssp.h>
+#include <stdarg.h>
+#ifdef HAVE_STDIO_H
+# include <stdio.h>
+#endif
+
+extern void __chk_fail (void) __attribute__((__noreturn__));
+
+#ifdef HAVE_USABLE_VSNPRINTF
+int
+__vsnprintf_chk (char *s, size_t n, int flags __attribute__((unused)),
+ size_t slen, const char *format, va_list arg)
+{
+ if (n > slen)
+ __chk_fail ();
+
+ return vsnprintf (s, n, format, arg);
+}
+#endif
--- /dev/null
+/* Checking vsprintf.
+ Copyright (C) 2005, 2009 Free Software Foundation, Inc.
+
+This file is part of GCC.
+
+GCC is free software; you can redistribute it and/or modify it under
+the terms of the GNU General Public License as published by the Free
+Software Foundation; either version 3, or (at your option) any later
+version.
+
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file. (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
+GCC is distributed in the hope that it will be useful, but WITHOUT ANY
+WARRANTY; without even the implied warranty of MERCHANTABILITY or
+FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+for more details.
+
+Under Section 7 of GPL version 3, you are granted additional
+permissions described in the GCC Runtime Library Exception, version
+3.1, as published by the Free Software Foundation.
+
+You should have received a copy of the GNU General Public License and
+a copy of the GCC Runtime Library Exception along with this program;
+see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
+<http://www.gnu.org/licenses/>. */
+
+#include "config.h"
+#include <ssp/ssp.h>
+#include <stdarg.h>
+#ifdef HAVE_LIMITS_H
+# include <limits.h>
+#endif
+#ifdef HAVE_STDIO_H
+# include <stdio.h>
+#endif
+
+extern void __chk_fail (void) __attribute__((__noreturn__));
+
+#ifdef HAVE_USABLE_VSNPRINTF
+int
+__vsprintf_chk (char *s, int flags __attribute__((unused)),
+ size_t slen, const char *format, va_list arg)
+{
+ int done;
+
+ if (slen > (size_t) INT_MAX)
+ done = vsprintf (s, format, arg);
+ else
+ {
+ done = vsnprintf (s, slen, format, arg);
+ if (done >= 0 && (size_t) done >= slen)
+ __chk_fail ();
+ }
+ return done;
+}
+#endif