Bug 6758 - vsyslog not thread-safe
Summary: vsyslog not thread-safe
Status: NEW
Alias: None
Product: uClibc
Classification: Unclassified
Component: Threads (show other bugs)
Version: 0.9.30.1
Hardware: Other Linux
: P5 major
Target Milestone: ---
Assignee: unassigned
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-01-06 17:24 UTC by crayor
Modified: 2014-01-08 12:23 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
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.