Skip to content

Commit b9738f5

Browse files
committed
Fix #79242: COM error constants don't match com_exception codes
Because a `HRESULT` is a `LONG`[1], no special treatment is required on x86 platforms to get appropriate values. On x64 platforms we prefer positive values, what we could accomplish by casting the `HRESULT` value to `ULONG` and then to `zend_long`, but since the current behavior is correct and the performance improvement is negligible, we defer that to master. [1] <https://docs.microsoft.com/en-us/windows/win32/winprog/windows-data-types#hresult>
1 parent 5e2ea00 commit b9738f5

File tree

3 files changed

+29
-1
lines changed

3 files changed

+29
-1
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ PHP NEWS
55
- COM:
66
. Fixed bug #66322 (COMPersistHelper::SaveToFile can save to wrong location).
77
(cmb)
8+
. Fixed bug #79242 (COM error constants don't match com_exception codes on
9+
x86). (cmb)
810

911
- PCRE:
1012
. Fixed bug #79188 (Memory corruption in preg_replace/preg_replace_callback

ext/com_dotnet/com_extension.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,11 +336,15 @@ PHP_MINIT_FUNCTION(com_dotnet)
336336

337337
#define COM_CONST(x) REGISTER_LONG_CONSTANT(#x, x, CONST_CS|CONST_PERSISTENT)
338338

339-
#define COM_ERR_CONST(x) { \
339+
#if SIZEOF_ZEND_LONG == 8
340+
# define COM_ERR_CONST(x) { \
340341
zend_long __tmp; \
341342
ULongToIntPtr(x, &__tmp); \
342343
REGISTER_LONG_CONSTANT(#x, __tmp, CONST_CS|CONST_PERSISTENT); \
343344
}
345+
#else
346+
# define COM_ERR_CONST COM_CONST
347+
#endif
344348

345349
COM_CONST(CLSCTX_INPROC_SERVER);
346350
COM_CONST(CLSCTX_INPROC_HANDLER);

ext/com_dotnet/tests/bug79242.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Bug #79242 (COM error constants don't match com_exception codes)
3+
--SKIPIF--
4+
<?php
5+
if (!extension_loaded('com_dotnet')) die('skip com_dotnet extension not available');
6+
if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platforms only");
7+
?>
8+
--FILE--
9+
<?php
10+
var_dump(
11+
DISP_E_DIVBYZERO,
12+
DISP_E_OVERFLOW,
13+
DISP_E_BADINDEX,
14+
MK_E_UNAVAILABLE
15+
);
16+
?>
17+
--EXPECT--
18+
int(-2147352558)
19+
int(-2147352566)
20+
int(-2147352565)
21+
int(-2147221021)
22+

0 commit comments

Comments
 (0)