Skip to content

Commit de73849

Browse files
committed
Fix #77621: Already defined constants are not properly reported
We must not check uninitialized values (i.e. `c.value`), and we have to use proper types for printf-style formats (i.e. `char *` instead of `zend_string *`).
1 parent 0ffa84d commit de73849

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ PHP NEWS
66
. Fixed bug #77589 (Core dump using parse_ini_string with numeric sections).
77
(Laruence)
88

9+
- COM:
10+
. Fixed bug #77621 (Already defined constants are not properly reported).
11+
(cmb)
12+
913
- PDO_OCI:
1014
. Support Oracle Database tracing attributes ACTION, MODULE,
1115
CLIENT_INFO, and CLIENT_IDENTIFIER. (Cameron Porter)

ext/com_dotnet/com_typeinfo.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,17 +197,17 @@ PHP_COM_DOTNET_API int php_com_import_typelib(ITypeLib *TL, int mode, int codepa
197197
SysFreeString(bstr_ids);
198198

199199
/* sanity check for the case where the constant is already defined */
200+
php_com_zval_from_variant(&value, pVarDesc->lpvarValue, codepage);
200201
if ((exists = zend_get_constant(c.name)) != NULL) {
201-
if (COMG(autoreg_verbose) && !compare_function(&results, &c.value, exists)) {
202-
php_error_docref(NULL, E_WARNING, "Type library constant %s is already defined", c.name);
202+
if (COMG(autoreg_verbose) && !compare_function(&results, &value, exists)) {
203+
php_error_docref(NULL, E_WARNING, "Type library constant %s is already defined", ZSTR_VAL(c.name));
203204
}
204205
zend_string_release(c.name);
205206
ITypeInfo_ReleaseVarDesc(TypeInfo, pVarDesc);
206207
continue;
207208
}
208209

209210
/* register the constant */
210-
php_com_zval_from_variant(&value, pVarDesc->lpvarValue, codepage);
211211
if (Z_TYPE(value) == IS_LONG) {
212212
c.flags = mode;
213213
ZVAL_LONG(&c.value, Z_LVAL(value));

ext/com_dotnet/tests/bug77621.phpt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Bug #77621 (Already defined constants are not properly reported)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('com_dotnet')) die('skip com_dotnet extension not available');
6+
?>
7+
--INI--
8+
com.autoregister_verbose=1
9+
--FILE--
10+
<?php
11+
define('ADSTYPE_INVALID', 0);
12+
$root = dirname(array_change_key_case($_SERVER, CASE_UPPER)['COMSPEC']);
13+
com_load_typelib("$root\activeds.tlb");
14+
?>
15+
===DONE===
16+
--EXPECTF--
17+
Warning: com_load_typelib(): Type library constant ADSTYPE_INVALID is already defined in %s on line %d
18+
===DONE===

0 commit comments

Comments
 (0)