php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #61584 when using readline_info to set line_buffer, it causes memory corruption
Submitted: 2012-03-31 19:08 UTC Modified: 2012-05-22 14:23 UTC
From: osama dot sorour at eformations dot net Assigned:
Status: Open Package: Readline related
PHP Version: 5.4.0 OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2012-03-31 19:08 UTC] osama dot sorour at eformations dot net
Description:
------------
Using the function readline_info to set the property "line_buffer" performs a 
direct setting of readline rl_line_buffer. It works for short lived scripts but 
for longer ones, they start to crash randomly with sig violations.
The proper way for libreadline is to use rl_replace_line to set the line buffer.

In addition, readline_info does not allow you to set "point" and "end" properties 
that are needed when changing line_buffer.

I've included a patch that fixes the setting of "line_buffer" and adds the 
ability to set both "point" and "end" properties.

Test script:
---------------
None. Random crashes.

Expected result:
----------------
None.


Actual result:
--------------
None.

Patches

line_buffer-fix-end-point-set (last revision 2012-03-31 19:57 UTC by osama dot sorour at eformations dot net)

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-05-20 23:32 UTC] felipe@php.net
-Status: Open +Status: Feedback
 [2012-05-20 23:32 UTC] felipe@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.


 [2012-05-22 14:23 UTC] osama dot sorour at eformations dot net
-Status: Feedback +Status: Open
 [2012-05-22 14:23 UTC] osama dot sorour at eformations dot net
It is almost impossible to make it happen on purpose. It happened in my code, 
which was thousands of lines long with about 30 classes. In addition, when it 
used to happen, it used to happen randomly at different locations.

Please note that regardless of reproduction, the method used in the current code 
to set the readline buffer is wrong. Please refer to the patch and readline 
documentation:

Variable: char * rl_line_buffer
This is the line gathered so far. You are welcome to modify the contents of the 
line, but see 2.4.5 Allowing Undoing. The function rl_extend_line_buffer is 
available to increase the memory allocated to rl_line_buffer.

which clearly indicates that you are only allowed to change it, not replace the 
buffer pointer as it is done in the current code.

From the readline documentation, here is the correct way of completely replacing 
the buffer:

Function: void rl_replace_line (const char *text, int clear_undo)
Replace the contents of rl_line_buffer with text. The point and mark are 
preserved, if possible. If clear_undo is non-zero, the undo list associated with 
the current line is cleared.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Sun Dec 08 05:01:23 2019 UTC