# Race condition in PDOStatement (patch)

- Thread: https://externals.io/message/45851
- Original archive: https://news-web.php.net/php.internals/45851
- Started by Basant Kukreja on 2009-10-20T23:03:41+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #45851 — Basant Kukreja — 2009-10-20T23:03:41+00:00

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

Hi,
    There is a race condition in pdo's
PDOStatement->ce.default_properties.ref_count. The integer
is incremented without any lock around it (or using any other atomic APIs).
This causes PDO to crash under stress. Details are given in bug report
http://bugs.php.net/bug.php?id=49937&thanks=1

I have attached the patch for review.

Note :
I could not find any easy locking mechanism available in php sources so needed
to use tsrm_mutex to implement atomic increments. It can be done very
efficiently in many modern OSes but for php 5.2.x, I didn't want to introduce
many changes.

---

## #45875 — Basant Kukreja — 2009-10-23T18:21:57+00:00

URL: https://externals.io/message/45851#45875 · In reply to: #45851

I have revised the patch for the race condition. New patch is much
less invasive and
scope of the change is restricted to pdo only.

Details are there in the bug.
Patch is attached.

Regards,
Basant.

On Tue, Oct 20, 2009 at 4:03 PM, Basant Kukreja
<basant.kukreja@gmail.com> wrote:
> Hi,
>    There is a race condition in pdo's
> PDOStatement->ce.default_properties.ref_count. The integer
> is incremented without any lock around it (or using any other atomic APIs).
> This causes PDO to crash under stress. Details are given in bug report
> http://bugs.php.net/bug.php?id=49937&thanks=1
>
> I have attached the patch for review.
>
> Note :
> I could not find any easy locking mechanism available in php sources so needed
> to use tsrm_mutex to implement atomic increments. It can be done very
> efficiently in many modern OSes but for php 5.2.x, I didn't want to introduce
> many changes.
