Skip Menu |

This queue is for tickets about the Log-Log4perl CPAN distribution.

Report information
The Basics
Id: 121346
Status: resolved
Priority: 0/
Queue: Log-Log4perl

People
Owner: Nobody in particular
Requestors: kgabi [...] freemail.hu
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Log::Log4perl::Appender::File dies when writing zero length (or undef) message
Date: Mon, 24 Apr 2017 10:37:31 +0200 (CEST)
To: "bug-Log-Log4perl [...] rt.cpan.org" <bug-log-log4perl [...] rt.cpan.org>
From: kgabi <kgabi [...] freemail.hu>
In version 1.49 appeared the old #67132 bug: If the message has zero bytes to it, it will die, and $! will not be set. The problem is checking the syswrite return value:   my $rc &#61;   syswrite( $fh,     $self-&gt;{ syswrite_encoder } ?       $self-&gt;{ syswrite_encoder }-&gt;($params{message}) :       $params{message} ); if(!$rc) {<!-- -->   die &#34;Cannot syswrite to &#39;$self-&gt;{filename}&#39;: $!&#34;; } This is not quite right. That is, syswrite returns undef on failure, a return of 0 merely means that syswrite wrote nothing. The correct way to do this would be: if(!defined $rc) {<!-- -->   die &#34;Cannot syswrite to &#39;$self-&gt;{filename}&#39;: $!&#34;; } Version 1.48 worked fine: defined (syswrite $fh, $params{message}) or   die &#34;Cannot syswrite to &#39;$self-&gt;{filename}&#39;: $!&#34;; Regards, Gabor Kanizsai ​​​​​​​  
Subject: [rt.cpan.org #121346] Log::Log4perl::Appender::File dies when writing zero length (or undef) message
Date: Mon, 24 Apr 2017 11:39:33 +0200 (CEST)
To: "bug-Log-Log4perl [...] rt.cpan.org" <bug-log-log4perl [...] rt.cpan.org>
From: kgabi <kgabi [...] freemail.hu>
Once again:) In version 1.49 appeared the old #67132 bug: If the message has zero bytes to it, it will die, and $! will not be set. The problem is checking the syswrite return value:   my $rc &#61;   syswrite( $fh,     $self-&gt;{ syswrite_encoder } ?       $self-&gt;{ syswrite_encoder }-&gt;($params{message}) :       $params{message} ); if(!$rc) {<!-- -->   die &#34;Cannot syswrite to &#39;$self-&gt;{filename}&#39;: $!&#34;; } This is not quite right. That is, syswrite returns undef on failure, a return of 0 merely means that syswrite wrote nothing. The correct way to do this would be: if(!defined $rc) {<!-- -->   die &#34;Cannot syswrite to &#39;$self-&gt;{filename}&#39;: $!&#34;; } Version 1.48 worked fine: defined (syswrite $fh, $params{message}) or   die &#34;Cannot syswrite to &#39;$self-&gt;{filename}&#39;: $!&#34;; Regards, Gabor Kanizsai  
Thanks for reporting this issue, Gabor! I've applied the fix you proposed and added a test case to prevent future regressions: https://github.com/mschilli/log4perl/commit/2f4b27c8f924962b6270726a77fba3da5d830442