From dan@obluda.cz  Thu Dec 29 20:35:00 2011
Return-Path: <dan@obluda.cz>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id DC6CB106566B
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 29 Dec 2011 20:35:00 +0000 (UTC)
	(envelope-from dan@obluda.cz)
Received: from m8-64.freebsd.cz (m8-64.freebsd.cz [195.113.20.206])
	by mx1.freebsd.org (Postfix) with ESMTP id 64C5B8FC0C
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 29 Dec 2011 20:34:59 +0000 (UTC)
Received: from m8-64.freebsd.cz (localhost [127.0.0.1])
	by m8-64.freebsd.cz (8.14.4/8.14.4) with ESMTP id pBTK6lN0013279
	for <FreeBSD-gnats-submit@freebsd.org>; Thu, 29 Dec 2011 21:06:47 +0100 (CET)
	(envelope-from dan@obluda.cz)
Received: (from root@localhost)
	by m8-64.freebsd.cz (8.14.4/8.14.4/Submit) id pBTK6lkb013278;
	Thu, 29 Dec 2011 21:06:47 +0100 (CET)
	(envelope-from dan)
Message-Id: <201112292006.pBTK6lkb013278@m8-64.freebsd.cz>
Date: Thu, 29 Dec 2011 21:06:47 +0100 (CET)
From: Dan Lukes <dan@obluda.cz>
Reply-To: Dan Lukes <dan@obluda.cz>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: Broken logger logic (when -f option && long lines in file) 
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         163700
>Category:       bin
>Synopsis:       logger(1): broken 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:  Fri Dec 30 00:28:57 UTC 2011
>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:
