# thread unsafety inventory

- Thread: https://externals.io/message/26727
- Original archive: https://news-web.php.net/php.internals/26727
- Started by Ron Korving on 2006-11-27T20:24:09+00:00
- Messages: 4
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #26727 — Ron Korving — 2006-11-27T20:24:09+00:00

URL: https://externals.io/message/26727#26727

Internals,

I have gone through the PHP codebase (latest 5.2 CVS), looking for the use
of thread unsafe functions, and I found a number. I have virtually no
experience in the PHP codebase, so I can't guarantee there are no false
alarms in this, but I think the majority is valid. I noticed that
main/reentrancy.c provided in thread-safe versions of unsafe functions by
means of locking, which can be used when the thread-safe variant is not
available. These functions in reentrancy.c are not always used however.

Below follows all situations I could find. The only other functions I
checked besides those mentioned was asctime(), which showed no problems. If
you feel it's better for me to turn this into a bugreport (or many small
ones?), let me know and I will.

Kind regards,

Ron Korving

-------------------------------------------------

gmtime: (use gmtime_r)

ext/interbase/ibase_query.c on line 679
ext/pdo_sqlite/sqlite/src/date.c on line 948 (external code library)
sapi/thttpd_patch on lines 282, 1355, 2298


ctime: (use ctime_r)

ext/mime_magic/mime_magic.c on line 1759


localtime: (use localtime_r)

ext/com_dotnet/com_variant.c on line 818
ext/pdo_sqlite/sqlite/src/date.c on line 415 (external code library)
ext/sqlite/libsqlite/src/date.c on line 419 (external code library)
ext/xmlrpc/libxmlrpc/xmlrpc.c on line 234 (external code library)
ext/zip/lib/zip_dirent.c on lines 398, 525 (external code library)
sapi/thttpd_patch on line 2300 (external code library)


crypt: (use crypt_r)

ext/standard/crypt.c on line 149


rand: (use rand_r)

ext/mcrypt/mcrypt.c on line 1042
ext/soap/php_http.c on line 467
ext/sqlite/libsqlite/src/encode.c on lines 204, 213 (external code library)


readdir: (use readdir_r)

ext/pcre/pcrelib/pcregrep.c on line 261
main/streams/php_scandir.c on line 74

---

## #26730 — Ilia Alshanetsky — 2006-11-28T00:25:26+00:00

URL: https://externals.io/message/26727#26730 · In reply to: #26727

>
> rand: (use rand_r)
>
> ext/mcrypt/mcrypt.c on line 1042
> ext/soap/php_http.c on line 467

The first two are now fixed.

> ext/sqlite/libsqlite/src/encode.c on lines 204, 213 (external code  
> library)

These two uses are a non-issue as they are located inside an ifdefed  
out test code.

Thanks for the letting us know about these issues, I'll look over all  
the identified problems over the course of the week and apply patches  
where necessary.


Ilia Alshanetsky

---

## #26742 — Ilia Alshanetsky — 2006-11-30T16:39:01+00:00

URL: https://externals.io/message/26727#26742 · In reply to: #26727

> gmtime: (use gmtime_r)
>
> ext/interbase/ibase_query.c on line 679

Fixed.

> ext/pdo_sqlite/sqlite/src/date.c on line 948 (external code library)

This code cannot be reached since we compile libsqlite with date  
functions.

> sapi/thttpd_patch on lines 282, 1355, 2298

External application patch, can't be helped.

> ctime: (use ctime_r)
>
> ext/mime_magic/mime_magic.c on line 1759

Fixed.

> localtime: (use localtime_r)
>
> ext/com_dotnet/com_variant.c on line 818

Win32 only code and there localtime is already thread-safe.

> ext/pdo_sqlite/sqlite/src/date.c on line 415 (external code library)
> ext/sqlite/libsqlite/src/date.c on line 419 (external code library)
> ext/xmlrpc/libxmlrpc/xmlrpc.c on line 234 (external code library)
> ext/zip/lib/zip_dirent.c on lines 398, 525 (external code library)

Fixed. You may want to report the sqlite issues to sqlite devs so  
that they can apply a fix in their code base as well.

> sapi/thttpd_patch on line 2300 (external code library)

External application patch, can't be helped.

> crypt: (use crypt_r)
>
> ext/standard/crypt.c on line 149

Fixed.

> rand: (use rand_r)
>
> ext/mcrypt/mcrypt.c on line 1042
> ext/soap/php_http.c on line 467

Fixed.

> ext/sqlite/libsqlite/src/encode.c on lines 204, 213 (external code  
> library)

This code cannot be reached.

> readdir: (use readdir_r)
>
> ext/pcre/pcrelib/pcregrep.c on line 261

This code cannot be reached.

> main/streams/php_scandir.c on line 74

Fixed.

Ilia Alshanetsky

---

## #26743 — Ron Korving — 2006-11-30T21:00:11+00:00

URL: https://externals.io/message/26727#26743 · In reply to: #26742

Ilia,

Great work. I posted a bug report at www.sqlite.org.

Regards,

Ron Korving


"Ilia Alshanetsky" <ilia@prohost.org> wrote in message
news:773C5559-F08C-45EF-BCC1-211C26E93534@prohost.org...
>
> 
> > […]
>
> Fixed.
>
> > […]
>
> This code cannot be reached since we compile libsqlite with date
> functions.
>
> > […]
>
> External application patch, can't be helped.
>
> > […]
>
> Fixed.
>
> > […]
>
> Win32 only code and there localtime is already thread-safe.
>
> > […]
>
> Fixed. You may want to report the sqlite issues to sqlite devs so
> that they can apply a fix in their code base as well.
>
> > […]
>
> External application patch, can't be helped.
>
> > […]
>
> Fixed.
>
> > […]
>
> Fixed.
>
> > […]
>
> This code cannot be reached.
>
> > […]
>
> This code cannot be reached.
>
> > […]
>
> Fixed.
>
> Ilia Alshanetsky
