summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xdietlibc/mkrelease35
-rw-r--r--dietlibc/patches/0.29-r1/dietlibc-0.29-Makefile.patch92
-rw-r--r--dietlibc/patches/0.29-r1/dietlibc-0.29-arm-waitpid.patch13
-rw-r--r--dietlibc/patches/0.29-r1/dietlibc-0.29-dirent-prototype.patch15
-rw-r--r--dietlibc/patches/0.29-r1/dietlibc-0.29-hppa-sendrecvfrom.patch46
-rw-r--r--dietlibc/patches/0.29-r1/dietlibc-0.29-ia64-syscall-handling.patch55
-rw-r--r--dietlibc/patches/0.29-r1/dietlibc-0.29-nice.patch20
-rw-r--r--dietlibc/patches/0.29-r1/dietlibc-0.29-ppc32-userland-on-64bit.patch13
-rw-r--r--dietlibc/patches/0.29-r1/dietlibc-0.29-sparc-termios.patch15
-rw-r--r--dietlibc/patches/0.29-r1/dietlibc-0.29-ssp-support.patch58
-rw-r--r--dietlibc/tools/ssp.c129
11 files changed, 491 insertions, 0 deletions
diff --git a/dietlibc/mkrelease b/dietlibc/mkrelease
new file mode 100755
index 0000000..7f309c2
--- /dev/null
+++ b/dietlibc/mkrelease
@@ -0,0 +1,35 @@
+#!/bin/bash
+
+if [ -z $2 ]; then
+ echo "Usage: mkrelease <ver> <rev>"
+ exit 1
+fi
+
+VER="${1}"
+REV="${2}"
+
+shift 2
+
+tmpdir=$(mktemp -du)
+
+svn export . ${tmpdir}
+
+pushd ${tmpdir} >/dev/null
+pushd patches >/dev/null
+
+for dir in *; do
+ [ "${dir}" == "${VER}-${REV}" ] && mv ${dir}/* .
+ rm -rf "${dir}"
+done
+
+popd >/dev/null
+
+rm -f mkrelease
+
+popd >/dev/null
+
+tar cjvf ./dietlibc-${VER}-patches-${REV}.tar.bz2 -C ${tmpdir} . | sort
+
+rm -rf ${tmpdir}
+
+echo "Tarball is at ./dietlibc-${VER}-patches-${REV}.tar.bz2"
diff --git a/dietlibc/patches/0.29-r1/dietlibc-0.29-Makefile.patch b/dietlibc/patches/0.29-r1/dietlibc-0.29-Makefile.patch
new file mode 100644
index 0000000..6918275
--- /dev/null
+++ b/dietlibc/patches/0.29-r1/dietlibc-0.29-Makefile.patch
@@ -0,0 +1,92 @@
+Index: dietlibc-0.29/Makefile
+===================================================================
+--- dietlibc-0.29.orig/Makefile
++++ dietlibc-0.29/Makefile
+@@ -1,5 +1,5 @@
+ INSTALL=install
+-prefix?=/opt/diet
++prefix=/usr/diet
+ # Set the following to install to a different root
+ #DESTDIR=/tmp/fefix
+ # Use "make DEBUG=1" to compile a debug version.
+@@ -8,7 +8,7 @@ LIBDIR=${prefix}/lib
+ BINDIR=${prefix}/bin
+ MAN1DIR=${prefix}/man/man1
+
+-MYARCH:=$(shell uname -m | sed -e 's/i[4-9]86/i386/' -e 's/armv[3-6][lb]/arm/')
++MYARCH:=$(shell uname -m | sed -e 's/i[4-9]86/i386/' -e 's/armv[3-6][lb]/arm/' -e 's/sparc64/sparc/')
+
+ # This extra-ugly cruft is here so make will not run uname and sed each
+ # time it looks at $(OBJDIR). This alone sped up running make when
+@@ -94,9 +94,6 @@ WHAT= $(OBJDIR) $(OBJDIR)/start.o $(OBJD
+
+ all: $(WHAT)
+
+-profiling: $(OBJDIR)/libgmon.a $(OBJDIR)/pstart.o
+-
+-CFLAGS=-pipe -nostdinc
+ CROSS=
+
+ CC=gcc
+@@ -121,16 +118,10 @@ LIBDLOBJ=$(patsubst libdl/%.c,$(OBJDIR)/
+
+ LIBPTHREAD_OBJS=$(patsubst libpthread/%.c,$(OBJDIR)/%.o,$(shell ./threadsafe.sh)) $(OBJDIR)/__testandset.o
+
+-LIBGMON_OBJS=$(OBJDIR)/__mcount.o $(OBJDIR)/monitor.o $(OBJDIR)/profil.o
+-
+ include $(ARCH)/Makefile.add
+
+ LIBMATHOBJ=$(patsubst %,$(OBJDIR)/%,$(LIBMATH))
+
+-ifeq ($(CFLAGS),-pipe -nostdinc)
+-CFLAGS+=-O -fomit-frame-pointer
+-endif
+-
+ ifneq ($(DEBUG),)
+ CFLAGS = -g
+ COMMENT = :
+@@ -199,9 +190,6 @@ LIBLATIN1_OBJS=$(patsubst liblatin1/%.c,
+ $(OBJDIR)/liblatin1.a: $(LIBLATIN1_OBJS)
+ $(CROSS)ar cru $@ $^
+
+-$(OBJDIR)/libgmon.a: $(LIBGMON_OBJS)
+- $(CROSS)ar cru $@ $^
+-
+ $(OBJDIR)/libpthread.a: $(LIBPTHREAD_OBJS) dietfeatures.h
+ $(CROSS)ar cru $@ $(LIBPTHREAD_OBJS)
+
+@@ -347,20 +335,11 @@ $(OBJDIR)/liblatin1.a $(OBJDIR)/libcompa
+ $(INSTALL) -m 644 $(OBJDIR)/dietlibc.a $(DESTDIR)$(ILIBDIR)/libc.a
+ ifeq ($(MYARCH),$(ARCH))
+ $(INSTALL) $(OBJDIR)/diet-i $(DESTDIR)$(BINDIR)/diet
+- -$(INSTALL) $(PICODIR)/diet-dyn-i $(DESTDIR)$(BINDIR)/diet-dyn
+ endif
+ $(INSTALL) -m 755 $(OBJDIR)/elftrunc $(OBJDIR)/dnsd $(DESTDIR)$(BINDIR)
+- -$(INSTALL) $(OBJDIR)/pstart.o $(OBJDIR)/libgmon.a $(OBJDIR)/dyn_start.o $(OBJDIR)/dyn_stop.o $(DESTDIR)$(ILIBDIR)
+- -$(INSTALL) $(PICODIR)/libc.so $(DESTDIR)$(ILIBDIR)/libc.so
+- -$(INSTALL) $(PICODIR)/libpthread.so $(DESTDIR)$(ILIBDIR)/libpthread.so
+- -$(INSTALL) $(PICODIR)/libdl.so $(DESTDIR)$(ILIBDIR)/libdl.so
+- -$(INSTALL) $(PICODIR)/libcompat.so $(DESTDIR)$(ILIBDIR)/libcompat.so
+- -$(INSTALL) $(PICODIR)/libm.so $(DESTDIR)$(ILIBDIR)/libm.so
+- -$(INSTALL) $(PICODIR)/dyn_start.o $(DESTDIR)$(ILIBDIR)/dyn_dstart.o
+- -$(INSTALL) $(PICODIR)/dyn_stop.o $(DESTDIR)$(ILIBDIR)/dyn_dstop.o
+- -$(INSTALL) $(PICODIR)/dstart.o $(PICODIR)/dyn_so_start.o $(DESTDIR)$(ILIBDIR)
++ -$(INSTALL) $(OBJDIR)/dyn_start.o $(OBJDIR)/dyn_stop.o $(DESTDIR)$(ILIBDIR)
+ $(INSTALL) -m 644 diet.1 $(DESTDIR)$(MAN1DIR)/diet.1
+- if test -f $(PICODIR)/libc.so -a ! -f $(DESTDIR)/etc/diet.ld.conf; then echo "$(ILIBDIR)" > $(DESTDIR)/etc/diet.ld.conf; fi
++ if test -f $(PICODIR)/libc.so -a ! -f $(DESTDIR)/etc/diet.ld.conf; then mkdir $(DESTDIR)/etc; echo "$(ILIBDIR)" > $(DESTDIR)/etc/diet.ld.conf; fi
+ for i in `find include -name \*.h`; do install -m 644 -D $$i $(DESTDIR)$(prefix)/$$i; done
+
+ uninstall:
+Index: dietlibc-0.29/mips/Makefile.add
+===================================================================
+--- dietlibc-0.29.orig/mips/Makefile.add
++++ dietlibc-0.29/mips/Makefile.add
+@@ -9,6 +9,6 @@
+ ifeq ($(CROSS),mips-linux-)
+ ENDIAN=-EB
+ endif
+-CFLAGS+=$(ENDIAN) -Os -G 0 -fstrict-aliasing -fno-pic -mno-abicalls
++CFLAGS+=$(ENDIAN) -Os -fstrict-aliasing
+ VPATH:=mips:syscalls.s:$(VPATH)
+ LIBOBJ+=$(OBJDIR)/pread64.o $(OBJDIR)/pwrite64.o $(OBJDIR)/divdi3.o
diff --git a/dietlibc/patches/0.29-r1/dietlibc-0.29-arm-waitpid.patch b/dietlibc/patches/0.29-r1/dietlibc-0.29-arm-waitpid.patch
new file mode 100644
index 0000000..c0f9835
--- /dev/null
+++ b/dietlibc/patches/0.29-r1/dietlibc-0.29-arm-waitpid.patch
@@ -0,0 +1,13 @@
+Index: dietlibc-0.29/arm/syscalls.h
+===================================================================
+--- dietlibc-0.29.orig/arm/syscalls.h
++++ dietlibc-0.29/arm/syscalls.h
+@@ -6,7 +6,7 @@
+ #define __NR_write (__NR_SYSCALL_BASE+ 4)
+ #define __NR_open (__NR_SYSCALL_BASE+ 5)
+ #define __NR_close (__NR_SYSCALL_BASE+ 6)
+- /* 7 was sys_waitpid */
++#define __NR_waitpid (__NR_SYSCALL_BASE+ 7)
+ #define __NR_creat (__NR_SYSCALL_BASE+ 8)
+ #define __NR_link (__NR_SYSCALL_BASE+ 9)
+ #define __NR_unlink (__NR_SYSCALL_BASE+ 10)
diff --git a/dietlibc/patches/0.29-r1/dietlibc-0.29-dirent-prototype.patch b/dietlibc/patches/0.29-r1/dietlibc-0.29-dirent-prototype.patch
new file mode 100644
index 0000000..0d229e6
--- /dev/null
+++ b/dietlibc/patches/0.29-r1/dietlibc-0.29-dirent-prototype.patch
@@ -0,0 +1,15 @@
+Index: dietlibc-0.29/include/dirent.h
+===================================================================
+--- dietlibc-0.29.orig/include/dirent.h
++++ dietlibc-0.29/include/dirent.h
+@@ -37,8 +37,8 @@ int closedir (DIR *__dirp) __THROW;
+ struct dirent *readdir (DIR *__dirp) __THROW;
+ struct dirent64 *readdir64 (DIR *__dirp) __THROW;
+ void rewinddir (DIR *__dirp) __THROW;
+-void seekdir (DIR *__dirp, long int __pos) __THROW;
+-long int telldir (DIR *__dirp) __THROW;
++void seekdir (DIR *__dirp, off_t __pos) __THROW;
++off_t telldir (DIR *__dirp) __THROW;
+
+ int scandir(const char *dir, struct dirent ***namelist,
+ int (*selection)(const struct dirent *),
diff --git a/dietlibc/patches/0.29-r1/dietlibc-0.29-hppa-sendrecvfrom.patch b/dietlibc/patches/0.29-r1/dietlibc-0.29-hppa-sendrecvfrom.patch
new file mode 100644
index 0000000..3ad8d77
--- /dev/null
+++ b/dietlibc/patches/0.29-r1/dietlibc-0.29-hppa-sendrecvfrom.patch
@@ -0,0 +1,46 @@
+Index: dietlibc-0.29/parisc/clone.S
+===================================================================
+--- dietlibc-0.29.orig/parisc/clone.S
++++ dietlibc-0.29/parisc/clone.S
+@@ -37,4 +37,4 @@ __clone:
+ bl _exit,%r2 /* exit thread */
+ copy %r28,%r26 /* return -> arg0 */
+
+- iitlbp %r0,(%r0) /* DIE ! DIE ! */
++ iitlbp %r0,(%sr0,%r0) /* DIE ! DIE ! */
+Index: dietlibc-0.29/parisc/recvfrom.S
+===================================================================
+--- dietlibc-0.29.orig/parisc/recvfrom.S
++++ dietlibc-0.29/parisc/recvfrom.S
+@@ -1,3 +1,12 @@
+ #include "syscalls.h"
+
+-syscall(recvfrom, recvfrom);
++.level 1.1
++.globl recvfrom
++.type recvfrom,@function
++recvfrom:
++ /* Just load the arguments from the
++ stack into %r21 and %r22 */
++ ldw -56(%sr0, %sp), %r21 ; 0x78
++ ldw -52(%sr0, %sp), %r22 ; 0x74
++ b __unified_syscall
++ ldi __NR_recvfrom, %r20
+Index: dietlibc-0.29/parisc/sendto.S
+===================================================================
+--- dietlibc-0.29.orig/parisc/sendto.S
++++ dietlibc-0.29/parisc/sendto.S
+@@ -1,3 +1,12 @@
+ #include "syscalls.h"
+
+-syscall(sendto, sendto);
++.level 1.1
++.globl sendto
++.type sendto,@function
++sendto:
++ /* Just load the arguments from the
++ stack into %r21 and %r22 */
++ ldw -56(%sr0, %sp), %r21 ; 0x78
++ ldw -52(%sr0, %sp), %r22 ; 0x74
++ b __unified_syscall
++ ldi __NR_sendto, %r20
diff --git a/dietlibc/patches/0.29-r1/dietlibc-0.29-ia64-syscall-handling.patch b/dietlibc/patches/0.29-r1/dietlibc-0.29-ia64-syscall-handling.patch
new file mode 100644
index 0000000..a243dde
--- /dev/null
+++ b/dietlibc/patches/0.29-r1/dietlibc-0.29-ia64-syscall-handling.patch
@@ -0,0 +1,55 @@
+Index: dietlibc-0.29/diet.c
+===================================================================
+--- dietlibc-0.29.orig/diet.c
++++ dietlibc-0.29/diet.c
+@@ -40,7 +40,7 @@ static const char* Os[] = {
+ "s390","-Os","-fomit-frame-pointer",0,
+ "s390x","-Os","-fomit-frame-pointer",0,
+ "sh","-Os","-fomit-frame-pointer",0,
+- "ia64","-Os","-fno-omit-frame-pointer",0,
++ "ia64","-Os",0,
+ "x86_64","-Os","-fstrict-aliasing","-momit-leaf-frame-pointer","-mfancy-math-387",0,
+ 0};
+
+Index: dietlibc-0.29/ia64/clone.S
+===================================================================
+--- dietlibc-0.29.orig/ia64/clone.S
++++ dietlibc-0.29/ia64/clone.S
+@@ -37,5 +37,4 @@ __clone:
+ br.call.dptk.few b0=__error_unified_syscall
+ br.ret.sptk.few b0
+ .endp __clone
+-.endp __clone2
+ .size __clone, . - __clone
+Index: dietlibc-0.29/ia64/unified.S
+===================================================================
+--- dietlibc-0.29.orig/ia64/unified.S
++++ dietlibc-0.29/ia64/unified.S
+@@ -16,7 +16,6 @@
+ .text
+
+ .globl __unified_syscall
+-.proc __unified_syscall
+ .globl __error_unified_syscall
+ .proc __error_unified_syscall
+ .globl _exit
+@@ -27,6 +26,8 @@ _exit:
+ .endp _exit
+ .size _exit, . - _exit
+
++.proc __unified_syscall
++
+ __unified_syscall:
+ break.i 0x100000
+ movl r2=errno
+@@ -41,6 +42,9 @@ __error_unified_syscall:
+ br.ret.sptk.few rp
+
+ .endp __unified_syscall
++.size __unified_syscall, . - __unified_syscall
++
++.proc __error_unified_syscall
++
+ .endp __error_unified_syscall
+-.size __unified_syscall, __error_unified_syscall - __unified_syscall
+ .size __error_unified_syscall, . - __error_unified_syscall
diff --git a/dietlibc/patches/0.29-r1/dietlibc-0.29-nice.patch b/dietlibc/patches/0.29-r1/dietlibc-0.29-nice.patch
new file mode 100644
index 0000000..641e6c3
--- /dev/null
+++ b/dietlibc/patches/0.29-r1/dietlibc-0.29-nice.patch
@@ -0,0 +1,20 @@
+Index: dietlibc-0.29/lib/__nice.c
+===================================================================
+--- dietlibc-0.29.orig/lib/__nice.c
++++ dietlibc-0.29/lib/__nice.c
+@@ -1,9 +1,14 @@
+ #include "syscalls.h"
+ #include <sys/time.h>
+ #include <sys/resource.h>
++#include <errno.h>
+
+ #ifndef __NR_nice
+ int nice(int i) {
+- return setpriority(PRIO_PROCESS,0,getpriority(PRIO_PROCESS,0)+i);
++ if (setpriority(PRIO_PROCESS,0,getpriority(PRIO_PROCESS,0)+i) == -1) {
++ errno=EPERM;
++ return -1;
++ }
++ return getpriority(PRIO_PROCESS,0);
+ }
+ #endif
diff --git a/dietlibc/patches/0.29-r1/dietlibc-0.29-ppc32-userland-on-64bit.patch b/dietlibc/patches/0.29-r1/dietlibc-0.29-ppc32-userland-on-64bit.patch
new file mode 100644
index 0000000..9bfe140
--- /dev/null
+++ b/dietlibc/patches/0.29-r1/dietlibc-0.29-ppc32-userland-on-64bit.patch
@@ -0,0 +1,13 @@
+Index: dietlibc-0.29/Makefile
+===================================================================
+--- dietlibc-0.29.orig/Makefile
++++ dietlibc-0.29/Makefile
+@@ -8,7 +8,7 @@ LIBDIR=${prefix}/lib
+ BINDIR=${prefix}/bin
+ MAN1DIR=${prefix}/man/man1
+
+-MYARCH:=$(shell uname -m | sed -e 's/i[4-9]86/i386/' -e 's/armv[3-6][lb]/arm/' -e 's/sparc64/sparc/')
++MYARCH=ppc
+
+ # This extra-ugly cruft is here so make will not run uname and sed each
+ # time it looks at $(OBJDIR). This alone sped up running make when
diff --git a/dietlibc/patches/0.29-r1/dietlibc-0.29-sparc-termios.patch b/dietlibc/patches/0.29-r1/dietlibc-0.29-sparc-termios.patch
new file mode 100644
index 0000000..e2ff4cf
--- /dev/null
+++ b/dietlibc/patches/0.29-r1/dietlibc-0.29-sparc-termios.patch
@@ -0,0 +1,15 @@
+Index: dietlibc-0.29/include/termios.h
+===================================================================
+--- dietlibc-0.29.orig/include/termios.h
++++ dietlibc-0.29/include/termios.h
+@@ -202,8 +202,8 @@ struct termios {
+ #define VDISCARD 13
+ #define VWERASE 14
+ #define VLNEXT 15
+-#define VMIN 16
+-#define VTIME 17
++#define VMIN VEOF
++#define VTIME VEOL
+ #else /* arm, i386, parisc, s390, x86_64 */
+ #define VINTR 0
+ #define VQUIT 1
diff --git a/dietlibc/patches/0.29-r1/dietlibc-0.29-ssp-support.patch b/dietlibc/patches/0.29-r1/dietlibc-0.29-ssp-support.patch
new file mode 100644
index 0000000..d267e45
--- /dev/null
+++ b/dietlibc/patches/0.29-r1/dietlibc-0.29-ssp-support.patch
@@ -0,0 +1,58 @@
+Index: dietlibc-0.29/i386/start.S
+===================================================================
+--- dietlibc-0.29.orig/i386/start.S
++++ dietlibc-0.29/i386/start.S
+@@ -50,7 +50,9 @@ _start:
+ PUT_VAR %edi, __vsyscall, %edx
+ 1:
+ #endif
+-
++#ifdef __dietlibc__
++ call __guard_setup
++#endif
+ #ifdef WANT_DYNAMIC
+ call _dyn_start
+ #else
+Index: dietlibc-0.29/sparc/start.S
+===================================================================
+--- dietlibc-0.29.orig/sparc/start.S
++++ dietlibc-0.29/sparc/start.S
+@@ -31,6 +31,9 @@ _start:
+ be NULL. */
+
+ /* Let libc do the rest of the initialization, and call main. */
++#if 0 /* FIXME: __dietlibc__ */
++ call __guard_setup
++#endif
+ #ifdef WANT_DYNAMIC
+ call _dyn_start
+ #else
+Index: dietlibc-0.29/sparc64/start.S
+===================================================================
+--- dietlibc-0.29.orig/sparc64/start.S
++++ dietlibc-0.29/sparc64/start.S
+@@ -31,6 +31,9 @@ _start:
+ be NULL. */
+
+ /* Let libc do the rest of the initialization, and call main. */
++#if 0 /* FIXME: __dietlibc__ */
++ call __guard_setup
++#endif
+ #ifdef WANT_DYNAMIC
+ call _dyn_start
+ #else
+Index: dietlibc-0.29/x86_64/start.S
+===================================================================
+--- dietlibc-0.29.orig/x86_64/start.S
++++ dietlibc-0.29/x86_64/start.S
+@@ -35,6 +35,10 @@ _start:
+ popq %rdi
+ #endif
+
++#if 0 /* FIXME: __dietlibc__ */
++ call __guard_setup
++#endif
++
+ #ifdef WANT_DYNAMIC
+ call _dyn_start
+ #else
diff --git a/dietlibc/tools/ssp.c b/dietlibc/tools/ssp.c
new file mode 100644
index 0000000..9db8327
--- /dev/null
+++ b/dietlibc/tools/ssp.c
@@ -0,0 +1,129 @@
+/*
+ * Distributed under the terms of the GNU General Public License v2
+ * $Header: /var/cvsroot/gentoo-x86/dev-libs/dietlibc/files/ssp.c,v 1.2 2004/12/05 19:25:40 solar Exp $
+ *
+ * This is a modified version of Hiroaki Etoh's stack smashing routines
+ * implemented for glibc.
+ *
+ * The following people have contributed input to this code.
+ * Ned Ludd - <solar[@]gentoo.org>
+ * Alexander Gabert - <pappy[@]gentoo.org>
+ * The PaX Team - <pageexec[@]freemail.hu>
+ * Peter S. Mazinger - <ps.m[@]gmx.net>
+ * Yoann Vandoorselaere - <yoann[@]prelude-ids.org>
+ * Robert Connolly - <robert[@]linuxfromscratch.org>
+ * Cory Visi <cory@visi.name>
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdio.h>
+#include <string.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sys/time.h>
+
+#ifdef __PROPOLICE_BLOCK_SEGV__
+#define SSP_SIGTYPE SIGSEGV
+#elif __PROPOLICE_BLOCK_KILL__
+#define SSP_SIGTYPE SIGKILL
+#else
+#define SSP_SIGTYPE SIGABRT
+#endif
+
+unsigned long __guard = 0UL;
+
+void
+__guard_setup (void)
+{
+ size_t size;
+ if (__guard != 0UL)
+ return;
+
+#ifndef __SSP_QUICK_CANARY__
+ /*
+ * Attempt to open kernel pseudo random device if one exists before
+ * opening urandom to avoid system entropy depletion.
+ */
+ {
+ int fd;
+#ifdef HAVE_DEV_ERANDOM
+ if ((fd = open ("/dev/erandom", O_RDONLY)) == (-1))
+#endif
+ fd = open ("/dev/urandom", O_RDONLY);
+ if (fd != (-1))
+ {
+ size = read (fd, (char *) &__guard, sizeof (__guard));
+ close (fd);
+ if (size == sizeof (__guard))
+ return;
+ }
+ }
+#endif
+
+ /* If sysctl was unsuccessful, use the "terminator canary". */
+ __guard = 0xFF0A0D00UL;
+
+ {
+ /* Everything failed? Or we are using a weakened model of the
+ * terminator canary */
+ struct timeval tv;
+
+ gettimeofday (&tv, NULL);
+ __guard ^= tv.tv_usec ^ tv.tv_sec;
+ }
+}
+
+void
+__stack_smash_handler (char func[], int damaged)
+{
+ struct sigaction sa;
+ const char message[] = ": stack smashing attack in function ";
+ int bufsz, len;
+ char buf[512];
+ static char *__progname = "dietapp";
+
+ sigset_t mask;
+ sigfillset (&mask);
+
+ sigdelset (&mask, SSP_SIGTYPE); /* Block all signal handlers */
+ sigprocmask (SIG_BLOCK, &mask, NULL); /* except SIGABRT */
+
+ bufsz = sizeof (buf);
+ strcpy (buf, "<2>");
+ len = 3;
+
+ strncat (buf, __progname, sizeof (buf) - 4);
+ len = strlen (buf);
+
+ if (bufsz > len)
+ {
+ strncat (buf, message, bufsz - len - 1);
+ len = strlen (buf);
+ }
+ if (bufsz > len)
+ {
+ strncat (buf, func, bufsz - len - 1);
+ len = strlen (buf);
+ }
+
+ /* print error message */
+ write (STDERR_FILENO, buf + 3, len - 3);
+ write (STDERR_FILENO, "()\n", 3);
+
+ /* Make sure the default handler is associated with the our signal handler */
+ memset (&sa, 0, sizeof (struct sigaction));
+ sigfillset (&sa.sa_mask); /* Block all signals */
+ sa.sa_flags = 0;
+ sa.sa_handler = SIG_DFL;
+ sigaction (SSP_SIGTYPE, &sa, NULL);
+ (void) kill (getpid (), SSP_SIGTYPE);
+ _exit (127);
+}