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

Bug#2337: klogd sometimes re-logs old messages



Package: syslogd
Version: 1.2-16

klogd sometimes re-sends messages to syslogd, long after they were
originally logged.  The bug is caused by an incorrect use of strpbrk()
in "klogd.c".  strpbrk() is being called on a buffer that is not
necessarily null-terminated, and when the termination is absent, it
can scan past the current end of the buffer into old messages.

Here is a patch:

--- klogd.c.~1~	Mon Sep 19 16:53:16 1994
+++ ./klogd.c	Fri Feb 16 02:11:22 1996
@@ -301,6 +301,7 @@
 	auto int idx = 0;
 	static int index = 0;
 	auto char *nl;
+	auto char *pend = ptr + len;
 	static char line[LOG_LINE_LENGTH];

 	if ( debugging && (len != 0) )
@@ -327,8 +328,10 @@
 		memset(line, '\0', sizeof(line));

 	while (len) {
-		nl = strpbrk(ptr, "\r\n"); /* Find first line terminator */
-		if (nl) {
+		for (nl = ptr; nl < pend; nl += 1)
+			if ((*nl == '\n') || (*nl == '\r'))
+				break;
+		if (nl != pend) {
 			len -= nl - ptr + 1;
 			strncat(line, ptr, nl - ptr);
 			ptr = nl + 1;


Reply to: