New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[PATCH] Sys::Syslog is not thread-safe (can segfault) #16348
Comments
From salvet@ics.muni.czCreated by salvet@ics.muni.czSys::Syslog is not thread-safe, reopening syslog connection Perl Info
|
From salvet@ics.muni.czsys-syslog-xs-locking.patchIndex: perl-5.20.2/cpan/Sys-Syslog/Syslog.xs
===================================================================
--- perl-5.20.2.orig/cpan/Sys-Syslog/Syslog.xs
+++ perl-5.20.2/cpan/Sys-Syslog/Syslog.xs
@@ -31,6 +31,9 @@
static SV *ident_svptr;
+#ifdef USE_ITHREADS
+STATIC perl_mutex ident_mutex;
+#endif
#ifndef LOG_FAC
#define LOG_FACMASK 0x03f8
@@ -102,9 +105,21 @@ openlog_xs(ident, option, facility)
STRLEN len;
char* ident_pv;
CODE:
+#ifdef USE_ITHREADS
+ MUTEX_LOCK(&ident_mutex);
+#endif
+ if (ident_svptr) {
+ closelog();
+ SvREFCNT_dec(ident_svptr);
+ ident_svptr = NULL;
+ }
ident_svptr = newSVsv(ident);
ident_pv = SvPV(ident_svptr, len);
openlog(ident_pv, option, facility);
+#ifdef USE_ITHREADS
+ MUTEX_UNLOCK(&ident_mutex);
+#endif
+
void
syslog_xs(priority, message)
@@ -128,15 +143,25 @@ closelog_xs()
PREINIT:
U32 refcnt;
CODE:
- if (!ident_svptr)
- return;
- closelog();
- refcnt = SvREFCNT(ident_svptr);
- if (refcnt) {
- SvREFCNT_dec(ident_svptr);
- if (refcnt == 1)
+#ifdef USE_ITHREADS
+ MUTEX_LOCK(&ident_mutex);
+#endif
+ if (ident_svptr) {
+ closelog();
+ SvREFCNT_dec(ident_svptr);
ident_svptr = NULL;
}
+#ifdef USE_ITHREADS
+ MUTEX_UNLOCK(&ident_mutex);
+#endif
+
+BOOT:
+{
+#ifdef USE_ITHREADS
+ MUTEX_INIT(&ident_mutex);
+#endif
+ ident_svptr = 0;
+}
#else /* HAVE_SYSLOG */
|
From @jmdhOn Wed, 03 Jan 2018 02:25:12 -0800, salvet@ics.muni.cz wrote:
This is a report of a dual-lived module against an old version of Debian. I have advised the reporter to resubmit against rt.cpan.org and the latest version of Sys-Syslog and/or provide more information in the Debian bug report |
The RT System itself - Status changed from 'new' to 'open' |
From @tonycozOn Fri, 05 Jan 2018 02:53:08 -0800, dom wrote:
As you say, this should be reported upstream. Also, the patch appears incorrect - it has the potential to release an SV in a different thread from where it was created. Tony |
Discussion of this ticket petered out 4-1/2 years ago -- as did discussion in the Debian ticket cited above. I think this ticket can be closed. I will self-assign it for the purpose of closing it within 7 days unless someone wants to take the discussion forward. |
The patch is broken but the bug is real, it should be kept open. |
Okay -- but now we need a better patch which can be submitted upstream. Who can try to develop that? |
I'll have a stab at it |
Migrated from rt.perl.org#132679 (status was 'open')
Searchable as RT132679$
The text was updated successfully, but these errors were encountered: