|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2009-10-14 07:20 UTC] toorion at gmail dot com
Description:
------------
When use a empty string parameter "" or '' for function in javascript assign from php class it causes segmentation fault 11
Reproduce code:
---------------
class myClass
{
public function test( $str )
{
//any code
echo 'TestWrite';
}
}
$myclass = new myClass();
$js = new JSContext();
$js->assign("myclass", $myclass);
$js->evaluateScript( 'myclass.test("")' );
Actual result:
--------------
if I set $js->evaluateScript( 'myclass.test("123")' );
all work fine, but if just "" - Segmentation fault: 11 is appear.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 19:00:01 2025 UTC |
The following use case also fails with either a "Bus Error (10)" or a "Segmentation fault (11)". Reproduce code: --------------- $js = new JsContext(); $result = $js->evaluateScript("''"); // Note that the error only triggers when accessing the PHP variable var_dump($result); It seems that there is an error in spidermonkey.c:296 : /* then we retrieve the pointer to the string */ char *txt = JS_GetStringBytes(str); RETVAL_STRING(txt, strlen(txt)); The signature for RETVAL_STRING is RETVAL_STRING(string, duplicate), so for an empty string, strlen(txt) is 0 which indicates to not create a copy of the string. Perhaps changing it to: RETVAL_STRINGL(txt, strlen(txt), true) or: if (strlen(txt)) { RETVAL_STRING(txt, true); } else { RETVAL_EMPTY_STRING; } I'll try to apply those changes and report backGood news! I applied the changes indicated above and the bug with empty strings seem to be gone :) Note that I haven't done anything in C in years so please check that I've got it right. Index: spidermonkey.c =================================================================== --- spidermonkey.c (revision 53) +++ spidermonkey.c (working copy) @@ -293,7 +293,12 @@ { /* then we retrieve the pointer to the string */ char *txt = JS_GetStringBytes(str); - RETVAL_STRING(txt, strlen(txt)); + int len = strlen(txt); + if (len) { + RETVAL_STRINGL(txt, len, true); + } else { + RETVAL_EMPTY_STRING(); + } } else {