summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph M. Becker <cmbecker69@gmx.de>2020-02-07 18:04:14 +0100
committerChristoph M. Becker <cmbecker69@gmx.de>2020-02-07 18:04:14 +0100
commitb9738f5802d15ba5d593ae09a6e63e49f9d7880f (patch)
tree587885d6aa30d4d9ab0daf202cc0149bc2dfe033
parent5e2ea00b1539d6003548f7698ece1f737c14fb51 (diff)
downloadphp-git-b9738f5802d15ba5d593ae09a6e63e49f9d7880f.tar.gz
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>
-rw-r--r--NEWS2
-rw-r--r--ext/com_dotnet/com_extension.c6
-rw-r--r--ext/com_dotnet/tests/bug79242.phpt22
3 files changed, 29 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index 2c810370eb..86a6be63b4 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,8 @@ PHP NEWS
- COM:
. Fixed bug #66322 (COMPersistHelper::SaveToFile can save to wrong location).
(cmb)
+ . Fixed bug #79242 (COM error constants don't match com_exception codes on
+ x86). (cmb)
- PCRE:
. Fixed bug #79188 (Memory corruption in preg_replace/preg_replace_callback
diff --git a/ext/com_dotnet/com_extension.c b/ext/com_dotnet/com_extension.c
index a9fd0e7fde..025f6803df 100644
--- a/ext/com_dotnet/com_extension.c
+++ b/ext/com_dotnet/com_extension.c
@@ -336,11 +336,15 @@ PHP_MINIT_FUNCTION(com_dotnet)
#define COM_CONST(x) REGISTER_LONG_CONSTANT(#x, x, CONST_CS|CONST_PERSISTENT)
-#define COM_ERR_CONST(x) { \
+#if SIZEOF_ZEND_LONG == 8
+# define COM_ERR_CONST(x) { \
zend_long __tmp; \
ULongToIntPtr(x, &__tmp); \
REGISTER_LONG_CONSTANT(#x, __tmp, CONST_CS|CONST_PERSISTENT); \
}
+#else
+# define COM_ERR_CONST COM_CONST
+#endif
COM_CONST(CLSCTX_INPROC_SERVER);
COM_CONST(CLSCTX_INPROC_HANDLER);
diff --git a/ext/com_dotnet/tests/bug79242.phpt b/ext/com_dotnet/tests/bug79242.phpt
new file mode 100644
index 0000000000..46c5d8af3b
--- /dev/null
+++ b/ext/com_dotnet/tests/bug79242.phpt
@@ -0,0 +1,22 @@
+--TEST--
+Bug #79242 (COM error constants don't match com_exception codes)
+--SKIPIF--
+<?php
+if (!extension_loaded('com_dotnet')) die('skip com_dotnet extension not available');
+if (PHP_INT_SIZE != 4) die("skip this test is for 32bit platforms only");
+?>
+--FILE--
+<?php
+var_dump(
+ DISP_E_DIVBYZERO,
+ DISP_E_OVERFLOW,
+ DISP_E_BADINDEX,
+ MK_E_UNAVAILABLE
+);
+?>
+--EXPECT--
+int(-2147352558)
+int(-2147352566)
+int(-2147352565)
+int(-2147221021)
+