Skip to content

Commit fb92116

Browse files
committed
Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0: Fixed bug #73679 DOTNET read access violation using invalid codepage
2 parents 2c70581 + 1d80fb2 commit fb92116

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

ext/com_dotnet/com_dotnet.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ PHP_FUNCTION(com_dotnet_create_instance)
196196
int ret = FAILURE;
197197
char *where = "";
198198
IUnknown *unk = NULL;
199+
zend_long cp = CP_ACP;
199200

200201
php_com_initialize();
201202
stuff = (struct dotnet_runtime_stuff*)COMG(dotnet_runtime_stuff);
@@ -245,11 +246,17 @@ PHP_FUNCTION(com_dotnet_create_instance)
245246
if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "ss|l",
246247
&assembly_name, &assembly_name_len,
247248
&datatype_name, &datatype_name_len,
248-
&obj->code_page)) {
249+
&cp)) {
249250
php_com_throw_exception(E_INVALIDARG, "Could not create .Net object - invalid arguments!");
250251
return;
251252
}
252253

254+
if (Z_L(0) > cp || ZEND_LONG_INT_OVFL(cp)) {
255+
php_com_throw_exception(E_INVALIDARG, "Could not create .Net object - invalid codepage!");
256+
return;
257+
}
258+
obj->code_page = (int)cp;
259+
253260
oletype = php_com_string_to_olestring(datatype_name, datatype_name_len, obj->code_page);
254261
oleassembly = php_com_string_to_olestring(assembly_name, assembly_name_len, obj->code_page);
255262
oletype_sys = SysAllocString(oletype);

ext/com_dotnet/tests/bug73679.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Bug #73679 DOTNET read access violation using invalid codepage
3+
--SKIPIF--
4+
<?php # vim:ft=php
5+
if (!extension_loaded("com_dotnet")) print "skip COM/.Net support not present"; ?>
6+
--FILE--
7+
<?php
8+
9+
$stack = new DOTNET("mscorlib", "System.Collections.Stack", -2200000000);
10+
$stack->Push(".Net");
11+
$stack->Push("Hello ");
12+
echo $stack->Pop() . $stack->Pop();
13+
14+
?>
15+
--EXPECTF--
16+
Fatal error: Uncaught com_exception: Could not create .Net object - invalid codepage! in %sbug73679.php:%d
17+
Stack trace:
18+
#0 %sbug73679.php(%d): dotnet->dotnet('mscorlib', 'System.Collecti...', -2200000000)
19+
#1 {main}
20+
thrown in %sbug73679.php on line %d

0 commit comments

Comments
 (0)