Bug #75775 [NEW]: readline_read_history segfaults with empty file

From: Date: Mon, 08 Jan 2018 02:06:47 +0000
Subject: Bug #75775 [NEW]: readline_read_history segfaults with empty file
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-213414@lists.php.net to get a copy of this message
From: fernando at null-life dot com Operating system: Windows PHP version: 7.1.13 Package: Readline related Bug Type: Bug Bug description:readline_read_history segfaults with empty file Description: ------------ I believe the bug is caused by using strlen with null, fgets (probably) returns NULL on empty files. https://github.com/winlibs/wineditline/blob/master/src/history.c#L270 eof = fgets(&line[s], _EL_BUF_LEN, file); line_len = (int)strlen(line); Test script: --------------- <?php touch("empty.file"); readline_read_history("empty.file"); Expected result: ---------------- Nothing Actual result: -------------- (227c.1c20): Access violation - code c0000005 (first chance) First chance exceptions are reported before any exception handling. This exception may be expected and handled. php7!read_history+0xe3: 00007ff9`d89bb8c3 40383413 cmp byte ptr [rbx+rdx],sil ds:00000223`0ea15000=?? 0:000> k Child-SP RetAddr Call Site 000000acd79fbc20 00007ff9d884d87a php7!read_history+0xe3 [e:\repo\winlibs_wineditline\src\history.c @ 270] 000000acd79fbc70 00007ff9d872b875 php7!zif_readline_read_history+0x5a [c:\php-snap-build\php71\vc14\x64\php-7.1.13\ext\readline\readline.c @ 420] 000000acd79fbca0 00007ff9d8708aa0 php7!ZEND_DO_ICALL_SPEC_RETVAL_UNUSED_HANDLER+0x55 [c:\php-snap-build\php71\vc14\x64\php-7.1.13\zend\zend_vm_execute.h @ 638] 000000acd79fbce0 00007ff9d8751c7d php7!execute_ex+0x80 [c:\php-snap-build\php71\vc14\x64\php-7.1.13\zend\zend_vm_execute.h @ 432] 000000acd79fbd30 00007ff9d87519d9 php7!zend_execute+0x14d [c:\php-snap-build\php71\vc14\x64\php-7.1.13\zend\zend_vm_execute.h @ 475] 000000acd79fbd60 00007ff9d87517a7 php7!zend_execute_scripts+0xa9 [c:\php-snap-build\php71\vc14\x64\php-7.1.13\zend\zend.c @ 1483] 000000acd79fbde0 00007ff6a06128e6 php7!php_execute_script+0x277 [c:\php-snap-build\php71\vc14\x64\php-7.1.13\main\main.c @ 2577] 000000acd79fe990 00007ff6a061375e php!do_cli+0x996 [c:\php-snap-build\php71\vc14\x64\php-7.1.13\sapi\cli\php_cli.c @ 994] 000000acd79ff5b0 00007ff6a061b5a9 php!main+0x67e [c:\php-snap-build\php71\vc14\x64\php-7.1.13\sapi\cli\php_cli.c @ 1381] 000000acd79ff7c0 00007ffa10431fe4 php!__scrt_common_main_seh+0x11d [f:\dd\vctools\crt\vcstartup\src\startup\exe_common.inl @ 253] 000000acd79ff800 00007ffa124cefb1 KERNEL32!BaseThreadInitThunk+0x14 000000acd79ff830 0000000000000000 ntdll!RtlUserThreadStart+0x21 -- Edit bug report at https://bugs.php.net/bug.php?id=75775&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=75775&r=trysnapshot54 Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=75775&r=trysnapshot55 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=75775&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=75775&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=75775&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=75775&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=75775&r=needscript Try newer version: https://bugs.php.net/fix.php?id=75775&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=75775&r=support Expected behavior: https://bugs.php.net/fix.php?id=75775&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=75775&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=75775&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=75775&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=75775&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=75775&r=dst IIS Stability: https://bugs.php.net/fix.php?id=75775&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=75775&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=75775&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=75775&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=75775&r=mysqlcfg

« previous php.bugs (#213414) next »