Fixed Segmentation Fault on use (Bug #21578)

git-svn-id: https://svn.php.net/repository/pecl/expect/trunk@312414 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
michael
2011-06-23 20:43:19 +00:00
parent 9b925ac532
commit 178e5c07c5
4 changed files with 37 additions and 11 deletions

View File

@@ -173,6 +173,18 @@ PHP_MINIT_FUNCTION(expect)
REGISTER_LONG_CONSTANT("EXP_FULLBUFFER", EXP_FULLBUFFER, CONST_CS | CONST_PERSISTENT);
REGISTER_INI_ENTRIES();
Tcl_Interp *interp = Tcl_CreateInterp();
if (Tcl_Init(interp) == TCL_ERROR) {
php_error_docref (NULL TSRMLS_CC, E_ERROR,
"Unable to initialize TCL interpreter: %s", Tcl_GetStringResult (interp));
return FAILURE;
}
if (Expect_Init(interp) == TCL_ERROR) {
php_error_docref (NULL TSRMLS_CC, E_ERROR,
"Unable to initialize Expect: %s", Tcl_GetStringResult (interp));
return FAILURE;
}
return SUCCESS;
}
@@ -260,6 +272,8 @@ PHP_FUNCTION(expect_expectl)
php_stream_from_zval (stream, &z_stream);
if (!stream->wrapperdata) {
php_error_docref (NULL TSRMLS_CC, E_ERROR, "supplied argument is not a valid stream resource");
php_error_docref (NULL TSRMLS_CC, E_ERROR, "supplied argument is not a valid stream resource");
php_error_docref (NULL TSRMLS_CC, E_ERROR, "supplied argument is not a valid stream resource");
return;
}
@@ -327,15 +341,15 @@ PHP_FUNCTION(expect_expectl)
ecases_ptr++;
zend_hash_move_forward(Z_ARRVAL_P(z_cases));
}
ecases_ptr->pattern = estrdup("");
ecases_ptr->pattern = NULL;
ecases_ptr->re = NULL;
ecases_ptr->value = NULL;
ecases_ptr->type = exp_end;
key = exp_expectv (fd, ecases);
efree(ecases_ptr->pattern);
int exp_match_len = exp_match_end - exp_match;
if (z_match && exp_match && exp_match_len > 0) {
if (key >= 0 && z_match && exp_match && exp_match_len > 0) {
char *tmp = (char *)emalloc (sizeof(char) * (exp_match_len + 1));
strlcpy (tmp, exp_match, exp_match_len + 1);
zval_dtor (z_match);
@@ -344,7 +358,7 @@ PHP_FUNCTION(expect_expectl)
/* Get case that was matched */
matchedcase = ecases[key];
/* If there are subpattern matches ... */
if (matchedcase.re->startp != NULL) {
if (matchedcase.re != NULL && matchedcase.re->startp != NULL) {
int i;
/* iterate across all possible 9 subpatterns (a limitation of libexpect)
and add matching substring to matches array */
@@ -371,6 +385,15 @@ PHP_FUNCTION(expect_expectl)
RETURN_LONG (key);
}
// Free compiled patterns:
ecases_ptr = ecases;
while (ecases_ptr != NULL && ecases_ptr->type != exp_end) {
if (ecases_ptr->re != NULL) {
free(ecases_ptr->re);
}
ecases_ptr++;
}
efree (ecases);
}
/* }}} */

View File

@@ -14,11 +14,11 @@ http://pear.php.net/dtd/package-2.0.xsd">
<email>michael@php.net</email>
<active>yes</active>
</lead>
<date>2011-01-25</date>
<time>23:07:00</time>
<date>2011-06-23</date>
<time>23:40:00</time>
<version>
<release>0.2.9</release>
<api>0.2.9</api>
<release>0.3.0</release>
<api>0.3.0</api>
</version>
<stability>
<release>beta</release>
@@ -26,7 +26,8 @@ http://pear.php.net/dtd/package-2.0.xsd">
</stability>
<license uri="http://www.php.net/license">PHP License</license>
<notes>
Provide a default value for expect.match_max (Bug #21823)
Fixed setting INI parameters (Bug #22566)
Fixed Segmentation Fault on use (Bug #21578)
</notes>
<contents>
<dir name="/">

View File

@@ -30,6 +30,8 @@
#include <SAPI.h>
#include <ext/standard/info.h>
#include <tcl.h>
#include <expect_tcl.h>
#include <expect.h>
extern zend_module_entry expect_module_entry;

View File

@@ -1,7 +1,7 @@
--TEST--
PECL Bug #22566 CGI
--SKIPIF--
<?php if (!extension_loaded("expect") || php_sapi_name() == 'cli') print "skip"; ?>
<?php if (!extension_loaded("expect")) print "skip"; ?>
--FILE--
<?php
var_dump(ini_set('expect.timeout', 3));