>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:
_______________________________________________
[email protected] mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-bugs
To unsubscribe, send any mail to "[email protected]"

Reply via email to