Req #69175 [NEW]: posix_strerror is not thread-safe

From: Date: Tue, 03 Mar 2015 18:33:51 +0000
Subject: Req #69175 [NEW]: posix_strerror is not thread-safe
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-191100@lists.php.net to get a copy of this message
From:             james at jamesreno dot com
Operating system: Linux
PHP version:      5.6.6
Package:          POSIX related
Bug Type:         Feature/Change Request
Bug description:posix_strerror is not thread-safe

Description:
------------
As with alot of the PHP extensions some are not thread-safe by nature
however posix_strerror could easily be thread-safe by making a small
change to the way it operates and as such is fully capable of becoming
thread-safe. It is my impression that this use is not thread-safe (I
could be wrong).

The problem is that posix_strerror makes a call to strerror() which
returns a pointer to the string which may *not* be modified as it is
reused and overwritten by the next call to strerror. Instead
posix_strerror should call strerror_r which accepts a buffer and buffer
length and writes the data there instead.

Granted that PHP seems to be making a copy of the output for its own use
there is a possibility of a race condition occurring with other threads.
This is just a small potential improvement that shouldnt take much time
to implement and would be a a step forward for thread-safety. 

There may be other cases of thread-safety issues in the posix extension
but those can be tackled one at a time. This is just a very limited and
specific report for one use case. If someone wants to scan the entire
extension for said issues more power to them but I am just requesting
this particular case be resolved.

Test script:
---------------
<?php
 echo posix_strerror(110);
?>

Expected result:
----------------
No corruption should ever be possible to occur.

Actual result:
--------------
Corruption could possibly occur in a build utilizing multiple threads.

-- 
Edit bug report at https://bugs.php.net/bug.php?id=69175&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=69175&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=69175&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=69175&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=69175&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=69175&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=69175&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=69175&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=69175&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=69175&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=69175&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=69175&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=69175&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=69175&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=69175&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=69175&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=69175&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=69175&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=69175&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=69175&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=69175&r=mysqlcfg



Thread (2 messages)

« previous php.bugs (#191100) next »