Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 29 Dec 2011 21:06:47 +0100 (CET)
From:      Dan Lukes <dan@obluda.cz>
To:        FreeBSD-gnats-submit@FreeBSD.org
Subject:   bin/163700: Broken logger logic (when -f option && long lines in file) 
Message-ID:  <201112292006.pBTK6lkb013278@m8-64.freebsd.cz>
Resent-Message-ID: <201112292040.pBTKeEea057939@freefall.freebsd.org>

next in thread | raw e-mail | index | archive | help

>Number:         163700
>Category:       bin
>Synopsis:       Broken logger logic (when -f option && long lines in file)
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Dec 29 20:40:13 UTC 2011
>Closed-Date:
>Last-Modified:
>Originator:     Dan Lukes
>Release:        any supported release, HEAD
>Organization:
Obludarium
>Environment:
src/usr.bin/logger/logger.c

>Description:
	When /usr/bin/logger called with -f option, following fragment of code is executed:

 =======================
...
char ..., buf[1024];
...
while (fgets(buf, sizeof(buf), stdin) != NULL)
   logmessage(pri, tag, host, svcname, buf);
...
logmessage(int pri, const char *tag, const char *host, const char *svcname,
	   const char *buf)
{
...
		syslog(pri, "%s", buf);
		return; 
...
 =======================

It mean that so long line from source file is broken to 1023byte chunks and those chunks are sent to syslog one-by-one.

Unfortunatelly, the size 1024b limit of syslog messages does not apply to "user part" of message, but to complete compiled syslog message (including <%d> priority encoded on start of line).

So end of each 1023b chunk is lost.

>How-To-Repeat:
	Create file with very long line (>1024 bytes), call logger -f filename
>Fix:

	Not sure what's intended behavior here, but current behavior (line splitted, but end of every part is lost) seems to be bug. 

1. if long lines should be silently truncated, then all line chunk but the first needs to be ignored

2. if lines shoult be splitted then logged per partes the chunk size needs to be less than 1024. Unfortunatelly, it's not possible to define safe size as there are some unknown-length strings that may or may not be added to the message.

if [1] is prefered behavior then

 -- usr.bin/logger/logger.c ------------------------
while (fgets(buf, sizeof(buf), stdin) != NULL)
   logmessage(pri, tag, host, svcname, buf);
 ---------------------------------------------------

needs to be changed to something like:
 ---------------------------------------------------
while (fgets(buf, sizeof(buf), stdin) != NULL) {
   logmessage(pri, tag, host, svcname, buf);
   while (strlen(buf) == sizeof(buf)-1 && buf[sizeof(buf)-2] != '\n' && fgets(buf, sizeof(buf), stdin) != NULL);
}
 ---------------------------------------------------
>Release-Note:
>Audit-Trail:
>Unformatted:



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201112292006.pBTK6lkb013278>