Bug 6758

Summary: vsyslog not thread-safe
Product: uClibc Reporter: crayor
Component: ThreadsAssignee: unassigned
Status: NEW ---    
Severity: major CC: uclibc-cvs
Priority: P5    
Version: 0.9.30.1   
Target Milestone: ---   
Hardware: Other   
OS: Linux   
Host: Target:
Build:

Description crayor 2014-01-06 17:24:08 UTC
stdp = p = tbuf + sprintf(tbuf, "<%d>%.15s ", pri, ctime(&now) + 4);

Sadly, the above line of syslog.c module is not thread-safe. ctime_r() shall be used.
My application crashed in uClibc with a segfault (in asctime/memcpy) when one thread does libc_fork() while another thread uses vsyslog() even though vsyslog() is protected by a mutex by the application.

I am compiling for ARM and configured uClibc for using LinuxThreads. I am using 0.9.30.1 but the bug seems to exist in all newer versions up to the latest library version (I looked at master branch and 0.9.33 via the source-code  browsing website).

The proposed solution is to replace the line by something like this:

char time_str[26];
stdp = p = tbuf + sprintf(tbuf, "<%d>%.15s ", pri, ctime_r(&now, time_str) + 4);

Cheers,
crayor
Comment 1 Bernhard Reutner-Fischer 2014-01-08 12:23:33 UTC
I think this is fixed in the current stable release as well as on master.
Please confirm.