php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78272 calling preg_match() before pcntl_fork() will freeze child process
Submitted: 2019-07-10 15:32 UTC Modified: 2019-09-18 08:25 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: dams@php.net Assigned:
Status: Closed Package: PCRE related
PHP Version: 7.3.7 OS: OSX
Private report: No CVE-ID: None
 [2019-07-10 15:32 UTC] dams@php.net
Description:
------------
When preg_match (or another preg_*function) has been called before pcntl_fork(), and then, called again in the child process, the child process stops at the preg_match, and just hangs. 

No error, no crash. 

This was tested on OSX, and it couldn't be replicated on Debian. This may be specific to OSX.


It is reproductible with PHP 7.3.7. It works on 7.2, 7.1.

It may be related to https://bugs.php.net/bug.php?id=77260 

Test script:
---------------
<?php
// Uncomment the following to freeze child process
//        preg_match('/abc/', 'abcde', $r);

        $pid = pcntl_fork();
        if ($pid === 0) {
            print "Child start\n";
            preg_match('/abc/', 'abcde', $r);
            print_r($r);
            print "End child\n";
            exit(0);
        } else {
            print "Main start\n";
            sleep(3);
            print "End Main\n";
            exit(0);
        }
?>

Expected result:
----------------
Main start
Child start
Array
(
    [0] => abc
)
End child
End Main

Actual result:
--------------
Main start
Child start
End Main

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-07-10 15:37 UTC] nikic@php.net
Is it possible for you test whether this works on 7.4 (has an updated PCRE2)?
 [2019-07-10 15:37 UTC] nikic@php.net
And also whether it works if you set pcre.jit=0.
 [2019-07-10 16:03 UTC] dams@php.net
pcre.jit=0 fixes the problem, both with PHP 7.3 and 7.4.


pcre.jit=1 behave the same with php 7.3 and 7.4.
 [2019-07-11 10:59 UTC] nikic@php.net
I was not able to reproduce this issue on 7.4 on Darwin 16.0.0. I tried both NTS and ZTS builds.
 [2019-07-12 09:54 UTC] dams@php.net
Here is my build sequence : 

git pull
git checkout PHP-7.4; git pull
make clean
./buildconf --force
env YACC=`brew --prefix bison`/bin/bison ./configure \
    --prefix="/usr/local/opt/php74" \
    --with-config-file-path="/usr/local/etc/php71" \
    --with-config-file-scan-dir=/usr/local/etc/phpng/conf.d \
    --enable-mbstring \
    --enable-tokenizer \
    --with-curl=/usr/local/opt/curl/\
    --enable-mbstring \
    --with-sqlite3=/usr/local/Cellar/sqlite/3.28.0 \
    --with-sodium=/usr/local/opt/libsodium \
    --enable-json \
    --enable-pcntl \
    --disable-all
gmake -j`sysctl -n hw.logicalcpu_max`
gmake test


I have the last OSX patches : 
      System Version: macOS 10.14.5 (18F132)
      Kernel Version: Darwin 18.6.0
 [2019-09-18 08:25 UTC] nikic@php.net
-Status: Open +Status: Verified
 [2019-09-18 08:25 UTC] nikic@php.net
Reproduced on CI.
 [2019-09-18 08:45 UTC] nikic@php.net
Automatic comment on behalf of nikita.ppv@gmail.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=e11ed028706dbedc51ba71736de21db15890a1c0
Log: Fixed bug #78272
 [2019-09-18 08:45 UTC] nikic@php.net
-Status: Verified +Status: Closed
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Nov 13 21:01:42 2019 UTC