Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.96k stars 556 forks source link

Bug in Sys::Syslog in perl 5.8.0 #6252

Closed p5pRT closed 18 years ago

p5pRT commented 21 years ago

Migrated from rt.perl.org#20557 (status was 'resolved')

Searchable as RT20557$

p5pRT commented 21 years ago

From gahan@pschmidt.org

If this is the wrong place for this report I apologize. Please point me at the correct destination and I will forward this accordingly.

In the Sys​::Syslog​::syslog that's bundled with 5.8.0 around line 277 there's a spurious or more likely\, a misplaced "&connect unless $connnected;". Since it appears before the sub is finished parsing all it's parameters it breaks the %m/$! functionality by resetting $!.

So it either needs to be moved after the line​:

  $message = sprintf($mask\, @​_);

or

local($errno) = $!;

needs to be added at the beginnning of the function and

  $mask =~ s/%m/$!/g;

needs to be changed to

  $mask =~ s/%m/$errno/g;

Thanx for all the work you all put into making perl the treasure it is. Hope this helps.

Cheers\, Paul R. Schmidt gahan@​pschmidt.org

p5pRT commented 21 years ago

From @floatingatoll

[gahan@​pschmidt.org - Sun Jan 26 13​:45​:24 2003]​:

If this is the wrong place for this report I apologize. Please point me at the correct destination and I will forward this accordingly.

You've got the right place :)

In the Sys​::Syslog​::syslog that's bundled with 5.8.0 around line 277 there's a spurious or more likely\, a misplaced "&connect unless $connnected;". Since it appears before the sub is finished parsing all it's parameters it breaks the %m/$! functionality by resetting $!.

Here's a patch against the development branch of Perl\, that applies this fix; if it's accepted\, it'll be in the next release of Perl.

Thanks!

- R.

# attached\, in case of whitespace mangling

Inline Patch ```diff --- ext/Sys/Syslog/Syslog.pm.orig 2003-02-15 01:38:53.000000000 -0500 +++ ext/Sys/Syslog/Syslog.pm 2003-02-15 01:39:48.000000000 -0500 @@ -230,6 +230,7 @@ } sub syslog { + local($errno) = shift; local($priority) = shift; local($mask) = shift; local($message, $whoami); @@ -282,7 +283,7 @@ $whoami .= "[$$]" if $lo_pid; - $mask =~ s/%m/$!/g; + $mask =~ s/%m/$errno/g; $mask .= "\n" unless $mask =~ /\n$/; $message = sprintf ($mask, @_); ```
p5pRT commented 21 years ago

From @floatingatoll

20557-save_errno.patch ```diff --- ext/Sys/Syslog/Syslog.pm.orig 2003-02-15 01:38:53.000000000 -0500 +++ ext/Sys/Syslog/Syslog.pm 2003-02-15 01:39:48.000000000 -0500 @@ -230,6 +230,7 @@ } sub syslog { + local($errno) = shift; local($priority) = shift; local($mask) = shift; local($message, $whoami); @@ -282,7 +283,7 @@ $whoami .= "[$$]" if $lo_pid; - $mask =~ s/%m/$!/g; + $mask =~ s/%m/$errno/g; $mask .= "\n" unless $mask =~ /\n$/; $message = sprintf ($mask, @_); ```
p5pRT commented 21 years ago

@floatingatoll - Status changed from 'new' to 'open'

p5pRT commented 21 years ago

From gahan@pschmidt.org

This fix will break the whole interface to the syslog function for anything that currently uses it. Also if the caller needs to explicitly pass the errno into the function then they're better off doing it manually via the printf style format and args than putting it at the head of the parm list.

Your fix would work fine if you changed the​:

  local($errno) = shift;

to​:

  local($errno) = $!;

or to avoid adding any additional code just move the first "&connect unless $connnected;" after the block of code that follows it (where the value of errno is substituted into the format string". I guess I don't understand why the "&connect unless $connnected;" that is breaking the defined functionality of the routine needs to be buried in the middle of the code to parse options.

--

Cheers\, Paul R. Schmidt gahan@​pschmidt.org

On 15 Feb 2003\, crystalflame wrote​:

Date​: 15 Feb 2003 06​:42​:53 -0000 From​: crystalflame \perlbug\-followup@​perl\.org To​: gahan@​pschmidt.org Subject​: [perl #20557] Bug in Sys​::Syslog in perl 5.8.0

[gahan@​pschmidt.org - Sun Jan 26 13​:45​:24 2003]​:

If this is the wrong place for this report I apologize. Please point me at the correct destination and I will forward this accordingly.

You've got the right place :)

In the Sys​::Syslog​::syslog that's bundled with 5.8.0 around line 277 there's a spurious or more likely\, a misplaced "&connect unless $connnected;". Since it appears before the sub is finished parsing all it's parameters it breaks the %m/$! functionality by resetting $!.

Here's a patch against the development branch of Perl\, that applies this fix; if it's accepted\, it'll be in the next release of Perl.

Thanks!

- R.

# attached\, in case of whitespace mangling --- ext/Sys/Syslog/Syslog.pm.orig 2003-02-15 01​:38​:53.000000000 -0500 +++ ext/Sys/Syslog/Syslog.pm 2003-02-15 01​:39​:48.000000000 -0500 @​@​ -230\,6 +230\,7 @​@​ }

sub syslog { + local($errno) = shift; local($priority) = shift; local($mask) = shift; local($message\, $whoami); @​@​ -282\,7 +283\,7 @​@​

 $whoami \.= "\[$$\]" if $lo\_pid;

- $mask =~ s/%m/$!/g; + $mask =~ s/%m/$errno/g; $mask .= "\n" unless $mask =~ /\n$/; $message = sprintf ($mask\, @​_);

p5pRT commented 21 years ago

From gahan@pschmidt.org

20557-save_errno.patch ```diff --- ext/Sys/Syslog/Syslog.pm.orig 2003-02-15 01:38:53.000000000 -0500 +++ ext/Sys/Syslog/Syslog.pm 2003-02-15 01:39:48.000000000 -0500 @@ -230,6 +230,7 @@ } sub syslog { + local($errno) = shift; local($priority) = shift; local($mask) = shift; local($message, $whoami); @@ -282,7 +283,7 @@ $whoami .= "[$$]" if $lo_pid; - $mask =~ s/%m/$!/g; + $mask =~ s/%m/$errno/g; $mask .= "\n" unless $mask =~ /\n$/; $message = sprintf ($mask, @_); ```
p5pRT commented 18 years ago

From @maddingue

The next release of Sys​::Syslog will include the modification to save errno before trying to connect. Thanks for your report.

-- Close the world\, txEn eht nepO.

p5pRT commented 18 years ago

From @maddingue

This is fixed in Sys​::Syslog 0.16\, now on the CPAN.

-- Close the world\, txEn eht nepO.

p5pRT commented 18 years ago

@rgs - Status changed from 'open' to 'resolved'