php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #59584 Segmentation Fault on use
Submitted: 2011-01-20 03:28 UTC Modified: 2011-06-23 16:44 UTC
From: iksmail at gmail dot com Assigned:
Status: Closed Package: expect (PECL)
PHP Version: 5_3 SVN-2011-01-20 (dev) OS: FreeBSD 7.2-RELEASE
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: iksmail at gmail dot com
New email:
PHP Version: OS:

 

 [2011-01-20 03:28 UTC] iksmail at gmail dot com
Description:
------------
I've used expect to connect through telnet to servers. When first some servers are accessible and next is inaccessible (timeout while connect), I've got memory fault.
When I first try to connect to inaccessible server, at the end I've got another error: /usr/Ports/work/usr/ports/lang/php5/work/php-5.3.5/main/streams/streams.c(400) : Stream of type 'STDIO' 0x2882762c (path:logs/192.168.188.40_2011_01_20_11_10_52.log) was not closed.
In code below $rows is an array of servers.

Reproduce code:
---------------
ini_set('expect.timeout', '3');
ini_set('expect.loguser', 'Off');
ini_set('expect.match_max', 10000);
	
$prompt = array(
'shell' => array('.*[>#].*', 'shell', 3),
'login' => array('>>User (name|password):', 'login', 3)
);
$expect_prompt = array_values($prompt);

foreach ($rows as $eqbase) {
	echo "start connect to {$eqbase['eqbase_ip']} ({$eqbase['eqbase_id']})\n";
			
	ini_set('expect.logfile', 'logs/'.$eqbase['eqbase_ip'].'_'.date('Y_m_d_H_i_s').'.log');
	$stream = expect_popen('telnet '.$eqbase['eqbase_ip']);
	echo "opened\n";
	$res = expect_expectl($stream, $expect_prompt, $matches);
	$reason = '';
	switch ($res) {
		case EXP_EOF:
			$reason = "EOF reached\n";
			break;
		case EXP_TIMEOUT:
			$reason = "Timeout\n";
			break;
		case EXP_FULLBUFFER:
			$reason = "No prompt pattern matched\n";
			break;
	}
	echo $reason;
	if ($res < 0) {
		echo "closed\n";
		fclose($stream);
		continue;
	}
	fwrite($stream, "login\n");
	$res = expect_expectl($stream, $expect_prompt, $matches);
			
	fwrite($stream, "pass\n");
	$res = expect_expectl($stream, $expect_prompt, $matches);

	fwrite($stream, "quit\ny\n");
	$res = expect_expectl($stream, $expect_prompt, $matches);
	echo "closed\n";
	fclose($stream);
}

Actual result:
--------------
When first servers is accessible, I've got:

start connect to 192.168.189.28 (1017)
opened
closed
start connect to 192.168.188.5 (1019)
opened
closed
start connect to 192.168.188.40 (1030)
opened

Program received signal SIGSEGV, Segmentation fault.
0x290412b4 in zif_expect_expectl (ht=3, return_value=0x28829b7c, return_value_ptr=0x0, this_ptr=0x0, return_value_used=1) at /usr/home/iks/pecl/expect-0.2.8/expect.c:343
343					if (matchedcase.re->startp[i] != NULL) {
(gdb) bt
#0  0x290412b4 in zif_expect_expectl (ht=3, return_value=0x28829b7c, return_value_ptr=0x0, this_ptr=0x0, return_value_used=1) at /usr/home/iks/pecl/expect-0.2.8/expect.c:343
#1  0x08265479 in zend_do_fcall_common_helper_SPEC (execute_data=0x2930104c) at zend_vm_execute.h:316
#2  0x0826a3d2 in ZEND_DO_FCALL_SPEC_CONST_HANDLER (execute_data=0x2930104c) at zend_vm_execute.h:1606
#3  0x0826484d in execute (op_array=0x2881f1d8) at zend_vm_execute.h:107
#4  0x082349e4 in zend_execute_scripts (type=8, retval=0x0, file_count=3) at /usr/Ports/work/usr/ports/lang/php5/work/php-5.3.5/Zend/zend.c:1266
#5  0x081c8549 in php_execute_script (primary_file=0xbfbfebbc) at /usr/Ports/work/usr/ports/lang/php5/work/php-5.3.5/main/main.c:2280
#6  0x08302306 in main (argc=2, argv=0xbfbfecbc) at /usr/Ports/work/usr/ports/lang/php5/work/php-5.3.5/sapi/cli/php_cli.c:1197

When first server is inaccessible, I've got:

start connect to 192.168.188.40 (1030)
opened
Timeout
closed
start connect to 192.168.188.154 (1034)
opened
Timeout
closed
start connect to 192.168.188.196 (1347)
opened
closed
start connect to 192.168.180.133 (1378)
opened
closed
/usr/Ports/work/usr/ports/lang/php5/work/php-5.3.5/main/streams/streams.c(400) : Stream of type 'STDIO' 0x28829b78 (path:logs/192.168.180.133_2011_01_20_11_23_16.log) was not closed


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-01-20 03:32 UTC] iksmail at gmail dot com
Expect 0.2.8.
 [2011-01-20 04:21 UTC] iksmail at gmail dot com
libexpect version 5.43.0
 [2011-01-20 05:40 UTC] iksmail at gmail dot com
Hm. Sorry, but the second 'bug' closed. My PHP was compiled with DEBUG. When I recompile PHP without DEBUG, 'bug' disappear :)
 [2011-01-20 05:43 UTC] iksmail at gmail dot com
And now by first bug I've got:

start connect to 192.168.189.28 (1017)
opened
closed
start connect to 192.168.188.5 (1019)
opened
closed
start connect to 192.168.188.40 (1030)
opened
Timeout
closed
start connect to 192.168.188.154 (1034)
opened

Program received signal SIGSEGV, Segmentation fault.
0x2867798d in zif_expect_expectl (ht=3, return_value=0x2872523c, return_value_ptr=0x0, this_ptr=0x0, return_value_used=1) at /usr/home/iks/pecl/expect-0.2.8/expect.c:343
343					if (matchedcase.re->startp[i] != NULL) {
(gdb) bt
#0  0x2867798d in zif_expect_expectl (ht=3, return_value=0x2872523c, return_value_ptr=0x0, this_ptr=0x0, return_value_used=1) at /usr/home/iks/pecl/expect-0.2.8/expect.c:343
#1  0x081d7751 in zend_do_fcall_common_helper_SPEC ()
#2  0x081e5ff7 in ZEND_DO_FCALL_SPEC_CONST_HANDLER ()
#3  0x081b416a in execute ()
#4  0x08191fc3 in zend_execute_scripts ()
#5  0x08142cfb in php_execute_script ()
#6  0x0820bad5 in main ()
#7  0xbfbfec28 in ?? ()
#8  0x00000007 in ?? ()
#9  0x082ab620 in HARDCODED_INI ()
#10 0x082c30c0 in zend_user_opcode_handlers ()
#11 0x082afc40 in zend_user_opcodes ()
#12 0x00000000 in ?? ()
#13 0x00000002 in ?? ()
#14 0x282b2b36 in dlopen () from /libexec/ld-elf.so.1
#15 0x0805aca9 in _start ()
#16 0x00000002 in ?? ()
 [2011-06-23 16:44 UTC] spektom at gmail dot com
Thank you for your bug report. This issue has been fixed
in the latest released version of the package, which you can download at
http://pecl.php.net/get/expect


 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Mon May 20 08:01:26 2019 UTC