[PATCH] Handle syslog stack overflow

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



syslog is printf like function with dynamic number of arguments.
Previously, logged string was passed directly as format string,
and if formating characters was included, stack overflow/underflow
can happen, resulting in segfault.

Also if messages was dropped, only formating string was printed
without substitution of passed variables. Now dropped log message
is only appended to formating string and standard vprintf substitution
is used.

Signed-off-by: Jan Friesse <jfriesse@xxxxxxxxxx>
---
 branches/whitetank/exec/print.c |   11 ++++++-----
 1 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/branches/whitetank/exec/print.c b/branches/whitetank/exec/print.c
index 4a0aa92..87eaec6 100644
--- a/branches/whitetank/exec/print.c
+++ b/branches/whitetank/exec/print.c
@@ -169,7 +169,7 @@ static void log_printf_worker_fn (void *thread_data, void *work_item)
 	}
 
 	if (logmode & LOG_MODE_SYSLOG) {
-		syslog (log_data->level, &log_data->log_string[log_data->syslog_pos]);
+		syslog (log_data->level, "%s", &log_data->log_string[log_data->syslog_pos]);
 	}
 	free (log_data->log_string);
 }
@@ -181,6 +181,7 @@ static void _log_printf (char *file, int line,
 	char newstring[4096];
 	char log_string[4096];
 	char char_time[512];
+	char dropped_log_msg[128];
 	struct timeval tv;
 	int i = 0;
 	int len;
@@ -219,12 +220,12 @@ static void _log_printf (char *file, int line,
 		if (newstring[strlen (newstring) - 1] == '\n') {
 			newstring[strlen (newstring) - 1] = '\0';
 		}
-		len = sprintf (log_string,
-			"%s - prior to this log entry, openais logger dropped '%d' messages because of overflow.", newstring, dropped_log_entries + 1);
-	} else {
-		len = vsprintf (log_string, newstring, ap);
+		sprintf (dropped_log_msg, " - prior to this log entry, openais logger dropped '%d' messages because of overflow.", dropped_log_entries + 1);
+		strcat (newstring, dropped_log_msg);
 	}
 
+	len = vsprintf (log_string, newstring, ap);
+
 	/*
 	** add line feed if not done yet
 	*/
-- 
1.7.4.1

_______________________________________________
discuss mailing list
discuss@xxxxxxxxxxxx
http://lists.corosync.org/mailman/listinfo/discuss


[Index of Archives]     [Linux Clusters]     [Corosync Project]     [Linux USB Devel]     [Linux Audio Users]     [Photo]     [Yosemite News]    [Yosemite Photos]    [Linux Kernel]     [Linux SCSI]     [X.Org]

  Powered by Linux