php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31040 Bad parameters when getting some events from browser
Submitted: 2004-12-09 18:24 UTC Modified: 2005-03-03 14:10 UTC
Votes:17
Avg. Score:4.6 ± 0.7
Reproduced:14 of 14 (100.0%)
Same Version:9 (64.3%)
Same OS:13 (92.9%)
From: jeanpierre dot vincent at gmail dot com Assigned: wez (profile)
Status: Closed Package: COM related
PHP Version: 5.0.2 OS: W2K WinXP
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: jeanpierre dot vincent at gmail dot com
New email:
PHP Version: OS:

 

 [2004-12-09 18:24 UTC] jeanpierre dot vincent at gmail dot com
Description:
------------
For some events of the IE browser, parameters given take value 0 and are of boolean type.
For example : BeforeNavigate2, BeforeNavigate and CommandStateChange, whereas events like DocumentComplete work fine.
Here is the example code from http://www.php.net/com-event-sink, which I simply added BeforeNavigate2. Launch it from a browser or CLI.

Reproduce code:
---------------
class IEEventSinker {
  var $terminated = false;
// just after Browser understands he has to navigate
	function BeforeNavigate2(&$pDisp, &$url, &$Flags, &$TargetFrameName, &$PostData, &$Headers, &$Cancel) {
		foreach(func_get_args() as $id => $valeur) {
// if the problem occurs ...			
if($valeur == 0)
				print $id.' = '.$valeur.' of type '.variant_get_type($valeur)."\n";
		}
// if the problem doesnt, $url is filled
		if($url != 0)
			echo "you'll navigate on $url\n";
	}
// when all objects of page are loaded
	function DocumentComplete(&$dom, $url) {
		echo "Document $url complete\n";
	}
// when closing browser
	function OnQuit() {
		echo "Quit!\n";
		$this->terminated = true;
	}
}

$ie = new COM("InternetExplorer.Application");
// note that you don't need the & for PHP 5!
$sink = new IEEventSinker();
com_event_sink($ie, $sink, "DWebBrowserEvents2");
$ie->Visible = true;
$ie->Navigate("http://www.php.net");
while(!$sink->terminated) {
  com_message_pump(4000);
}
$ie = null;

Expected result:
----------------
you'll navigate on http://www.php.net/
Document http://www.php.net/ complete
Quit!

Actual result:
--------------
0 = 0 of type 11
1 = 0 of type 11
2 = 0 of type 11
3 = 0 of type 11
4 = 0 of type 11
5 = 0 of type 11
6 = 0 of type 11
Document http://www.php.net/ complete
Quit!

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-12-13 11:52 UTC] jeanpierre dot vincent at gmail dot com
this bug exists for all objects events sink.
Problem is in the function disp_invokeex() in file com_wrapper.c

the var zarg declared in the for loop to catch parameters is overwriten every time, so all parameters have the value of the last one.
The reason why it happened on some functions and not another depends of the compilation. We had here a random bug !!

the solution is to replace this code (in disp_invokeex() in file com_wrapper.c)
///////////////////////////bugged code/////////////////////
params = (zval ***)safe_emalloc(sizeof(zval **), pdp->cArgs, 0);
               for (i = 0; i < pdp->cArgs; i++) {

                       VARIANT *arg;
                       zval *zarg;

                       arg = &pdp->rgvarg[ pdp->cArgs - 1 - i];

                       trace("alloc zval for arg %d VT=%08x\n", i, V_VT(arg));

                       ALLOC_INIT_ZVAL(zarg[i]);
                       php_com_wrap_variant(zarg, arg, COMG(code_page) TSRMLS_CC);
                       params[i] = &zarg;

               }

///////////////////////////////////////////////////////

by this one :
////////////////////correct code/////////////////////
params = (zval ***)safe_emalloc(sizeof(zval **), pdp->cArgs, 0);
               for (i = 0; i < pdp->cArgs; i++) {

                       VARIANT *arg;
                       zval **zarg= NULL;

                       zarg=(zval **)safe_emalloc(sizeof(zval *), pdp->cArgs, 0);

                       arg = &pdp->rgvarg[ pdp->cArgs - 1 - i];

                       trace("alloc zval for arg %d VT=%08x\n", i, V_VT(arg));

                       ALLOC_INIT_ZVAL(zarg[i]);
                       php_com_wrap_variant(zarg[i], arg, COMG(code_page) TSRMLS_CC);
                       params[i] = &zarg[i];

               }
/////////////////////////////////////////////////////////

Hope you'll correct for the next version !
 [2005-02-28 21:18 UTC] sniper@php.net
Please try using this CVS snapshot:

  http://snaps.php.net/php5-latest.tar.gz
 
For Windows:
 
  http://snaps.php.net/win32/php5-win32-latest.zip


 [2005-03-03 13:52 UTC] jeanpierre dot vincent at gmail dot com
thanks for solving this bug in your latest release.
now we are actually working on software based on com technology and we are blocked by this another bug :
http://bugs.php.net/bug.php?id=32170.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 04:01:28 2024 UTC