summaryrefslogtreecommitdiffstats
path: root/lib/libc/sys/stack_protector.c
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>2015-11-25 00:16:40 +0000
committerderaadt <deraadt@openbsd.org>2015-11-25 00:16:40 +0000
commit0e278963f8f4a4e987b326a4bf9030162061a41e (patch)
tree19c2cef8c76e3ff452a4a788d1178300951a9b36 /lib/libc/sys/stack_protector.c
parentAdd a syscall stub for sendsyslog2(2), and use it in syslog_r(3), passing (diff)
downloadwireguard-openbsd-0e278963f8f4a4e987b326a4bf9030162061a41e.tar.xz
wireguard-openbsd-0e278963f8f4a4e987b326a4bf9030162061a41e.zip
Rather than using syslog(3) (which pulls in snprintf), creating the report
string using simpler strings functions and use sendsyslog2() directly. Also, use the LOG_CONS flag so that single-user reports are more clear. Use a buffer size of 1024 (from bluhm) discussed with guenther and matthew ok millert
Diffstat (limited to 'lib/libc/sys/stack_protector.c')
-rw-r--r--lib/libc/sys/stack_protector.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/lib/libc/sys/stack_protector.c b/lib/libc/sys/stack_protector.c
index e61a5f2f82f..b7d9a364ae2 100644
--- a/lib/libc/sys/stack_protector.c
+++ b/lib/libc/sys/stack_protector.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: stack_protector.c,v 1.19 2015/11/10 04:30:59 guenther Exp $ */
+/* $OpenBSD: stack_protector.c,v 1.20 2015/11/25 00:16:40 deraadt Exp $ */
/*
* Copyright (c) 2002 Hiroaki Etoh, Federico G. Schwindt, and Miodrag Vallat.
@@ -49,17 +49,27 @@ long __guard_local __dso_hidden __attribute__((section(".openbsd.randomdata")));
void
__stack_smash_handler(const char func[], int damaged)
{
- struct syslog_data sdata = SYSLOG_DATA_INIT;
- const char message[] = "stack overflow in function %s";
+ extern char *__progname;
struct sigaction sa;
sigset_t mask;
+ char buf[1024];
+ size_t len;
/* Immediately block all signal handlers from running code */
sigfillset(&mask);
sigdelset(&mask, SIGABRT);
sigprocmask(SIG_SETMASK, &mask, NULL);
- syslog_r(LOG_CRIT, &sdata, message, func);
+ /* <10> is LOG_CRIT */
+ len = strlcpy(buf, "<10>", sizeof buf);
+ strlcpy(buf + len, __progname, sizeof buf - len);
+
+ /* truncate progname in case it is too long */
+ buf[sizeof(buf) / 2] = '\0';
+ strlcat(buf, ": stack overflow in function ", sizeof buf);
+ strlcat(buf, func, sizeof buf);
+
+ sendsyslog2(buf, strlen(buf), LOG_CONS);
memset(&sa, 0, sizeof(sa));
sigemptyset(&sa.sa_mask);