Subject: | memory patcher and core dumps when closelog() is called twice |
Date: | Thu, 22 Apr 2010 18:10:04 +0200 |
To: | bug-Sys-Syslog [...] rt.cpan.org |
From: | Andreas Jaekel <jaekel [...] strato-rz.de> |
Hello!
I'd like to report a bug in Sys::Syslog, and submit a proposed fix.
Module: Sys::Syslog
Version: 0.27
Perl-Version: perl-5.10.1
OS: Sun Solaris 10, but that probably does not matter.
The problem:
When the used protocol is "native", closelog() has a C-part
and a perl part. Neither protects against a memory
corruption bug that triggers if closelog() is called twice.
The C part (or XS part) reduces a ref count of an internal
scalar value, but doesn't invalidate the pointer. If it's called
again, it reduces the reference count of whatever happens
to be where it's internal scalar used to live.
As perl re-uses these structures, something is bound to be
there, and perl's internal state will be corrupted.
A demo perl source is attached to this mail
to demonstrate the problem.
The fix:
This can be fixed in the perl source, or in the XS source.
The patch attachted to this mail does both.
In the perl source, disconnect_log() is patched so that
closelog_xs() will only be called once, but the "native"
protocol is pushed back into @fallbackMethods so
that it is available for next time.
In the XS source, the reference count it checked to see
whether it'll drop to zero. If so, ident_svptr will be set to
NULL. If closelog_xs() is called again, without an
openlog_xs() in between, it'll see that ident_svptr is
NULL and return without harming any innocent perl
variables.
I had all kinds and flavors of perl errors in my log files
because of this. Variables suddenly became undefined,
Hashes transformed to "UNKNOWN"s, modules
miracolously "lost" functions, core files showed free()s
on non-acclocated memory and so on. Quite a
bit of fun :)
I hope this was helpful and I'd appreciate feedback.
If there's anything you need that's not included in
this mail, please tell me.
Regards,
Andy
--
---------------------------------------------
Telefon: +49 (30) 39 802 520
Telefax: +49 (30) 39 802 165
Mail: jaekel@strato-rz.de
---------------------------------------------
Strato Rechenzentrum AG
Pascalstraße 10
10587 Berlin
---------------------------------------------
Vorsitzender des Aufsichtsrates: Axel Krieger
Vorstand: Damian Schmidt (Vorsitz),
Silvia Beßlich, Christoph Steffens, René Wienholtz
Amtsgericht Berlin-Charlottenburg HRB 79450
Message body is not shown because sender requested not to inline it.
Message body is not shown because sender requested not to inline it.