Bug 163700 - logger(1): broken logic when -f option && long lines in file
Summary: logger(1): broken logic when -f option && long lines in file
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: Unspecified
Hardware: Any Any
: Normal Affects Only Me
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-29 20:40 UTC by Dan Lukes
Modified: 2017-12-31 22:32 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Dan Lukes 2011-12-29 20:40:13 UTC
	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.

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);
}
 ---------------------------------------------------
How-To-Repeat: 	Create file with very long line (>1024 bytes), call logger -f filename
Comment 1 Eitan Adler freebsd_committer freebsd_triage 2017-12-31 08:01:44 UTC
For bugs matching the following criteria:

Status: In Progress Changed: (is less than) 2014-06-01

Reset to default assignee and clear in-progress tags.

Mail being skipped