Skip to content

Promote warnings to Error in COM extension #6141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions ext/com_dotnet/com_com.c
Original file line number Diff line number Diff line change
Expand Up @@ -746,35 +746,37 @@ PHP_FUNCTION(com_event_sink)
/* {{{ Print out a PHP class definition for a dispatchable interface */
PHP_FUNCTION(com_print_typeinfo)
{
zval *arg1;
zend_object *object_zpp;
zend_string *typelib_name_zpp = NULL;
char *ifacename = NULL;
char *typelibname = NULL;
size_t ifacelen;
zend_bool wantsink = 0;
php_com_dotnet_object *obj = NULL;
ITypeInfo *typeinfo;

if (FAILURE == zend_parse_parameters(ZEND_NUM_ARGS(), "z/|s!b", &arg1, &ifacename,
&ifacelen, &wantsink)) {
RETURN_THROWS();
}
ZEND_PARSE_PARAMETERS_START(1, 3)
Z_PARAM_OBJ_OF_CLASS_OR_STR(object_zpp, php_com_variant_class_entry, typelib_name_zpp)
Z_PARAM_OPTIONAL
Z_PARAM_STRING_OR_NULL(ifacename, ifacelen)
Z_PARAM_BOOL(wantsink)
ZEND_PARSE_PARAMETERS_END();

php_com_initialize();
if (Z_TYPE_P(arg1) == IS_OBJECT) {
CDNO_FETCH_VERIFY(obj, arg1);
if (object_zpp) {
obj = (php_com_dotnet_object*)object_zpp;
} else {
convert_to_string(arg1);
typelibname = Z_STRVAL_P(arg1);
typelibname = ZSTR_VAL(typelib_name_zpp);
}

typeinfo = php_com_locate_typeinfo(typelibname, obj, ifacename, wantsink ? 1 : 0);
if (typeinfo) {
php_com_process_typeinfo(typeinfo, NULL, 1, NULL, obj ? obj->code_page : COMG(code_page));
ITypeInfo_Release(typeinfo);
RETURN_TRUE;
} else {
zend_error(E_WARNING, "Unable to find typeinfo using the parameters supplied");
}

php_error_docref(NULL, E_WARNING, "Unable to find typeinfo using the parameters supplied");
RETURN_FALSE;
}
/* }}} */
Expand Down
2 changes: 1 addition & 1 deletion ext/com_dotnet/com_extension.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function variant_cmp(mixed $left, mixed $right, int $lcid = LOCALE_SYSTEM_DEFAUL

function variant_date_to_timestamp(variant $variant): ?int {}

function variant_date_from_timestamp(int $timestamp): variant|false {}
function variant_date_from_timestamp(int $timestamp): variant {}

function variant_get_type(variant $variant): int {}

Expand Down
4 changes: 2 additions & 2 deletions ext/com_dotnet/com_extension_arginfo.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: f78e9db58131f9d67021eaea4c3d4be75cafe2ac */
* Stub hash: 637bee9d71fb0d566ce38004eec8bc6f75656837 */

ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_variant_set, 0, 2, IS_VOID, 0)
ZEND_ARG_OBJ_INFO(0, variant, variant, 0)
Expand Down Expand Up @@ -63,7 +63,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_variant_date_to_timestamp, 0, 1,
ZEND_ARG_OBJ_INFO(0, variant, variant, 0)
ZEND_END_ARG_INFO()

ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_variant_date_from_timestamp, 0, 1, variant, MAY_BE_FALSE)
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_variant_date_from_timestamp, 0, 1, variant, 0)
ZEND_ARG_TYPE_INFO(0, timestamp, IS_LONG, 0)
ZEND_END_ARG_INFO()

Expand Down
7 changes: 4 additions & 3 deletions ext/com_dotnet/com_handlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,18 +203,19 @@ static int com_property_exists(zend_object *object, zend_string *member, int che

static int com_dimension_exists(zend_object *object, zval *member, int check_empty)
{
php_error_docref(NULL, E_WARNING, "Operation not yet supported on a COM object");
/* TODO Add support */
zend_throw_error(NULL, "Cannot check dimension on a COM object");
return 0;
}

static void com_property_delete(zend_object *object, zend_string *member, void **cache_slot)
{
php_error_docref(NULL, E_WARNING, "Cannot delete properties from a COM object");
zend_throw_error(NULL, "Cannot delete properties from a COM object");
}

static void com_dimension_delete(zend_object *object, zval *offset)
{
php_error_docref(NULL, E_WARNING, "Cannot delete properties from a COM object");
zend_throw_error(NULL, "Cannot delete dimension from a COM object");
}

static HashTable *com_properties_get(zend_object *object)
Expand Down
2 changes: 2 additions & 0 deletions ext/com_dotnet/com_iterator.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ zend_object_iterator *php_com_iter_get(zend_class_entry *ce, zval *object, int b
obj = CDNO_FETCH(object);

if (V_VT(&obj->v) != VT_DISPATCH && !V_ISARRAY(&obj->v)) {
/* TODO Promote to TypeError? */
php_error_docref(NULL, E_WARNING, "Variant is not an object or array VT=%d", V_VT(&obj->v));
return NULL;
}
Expand All @@ -172,6 +173,7 @@ zend_object_iterator *php_com_iter_get(zend_class_entry *ce, zval *object, int b
dims = SafeArrayGetDim(V_ARRAY(&obj->v));

if (dims != 1) {
/* TODO Promote to ValueError? */
php_error_docref(NULL, E_WARNING,
"Can only handle single dimension variant arrays (this array has %d)", dims);
goto fail;
Expand Down
1 change: 1 addition & 0 deletions ext/com_dotnet/com_misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ PHP_COM_DOTNET_API int php_com_safearray_get_elem(VARIANT *array, VARIANT *dest,
dims = SafeArrayGetDim(V_ARRAY(array));

if (dims != 1) {
/* TODO Promote to ValueError? */
php_error_docref(NULL, E_WARNING,
"Can only handle single dimension variant arrays (this array has %d)", dims);
return 0;
Expand Down
7 changes: 4 additions & 3 deletions ext/com_dotnet/com_saproxy.c
Original file line number Diff line number Diff line change
Expand Up @@ -288,18 +288,19 @@ static int saproxy_property_exists(zend_object *object, zend_string *member, int

static int saproxy_dimension_exists(zend_object *object, zval *member, int check_empty)
{
php_error_docref(NULL, E_WARNING, "Operation not yet supported on a COM object");
/* TODO Add support */
zend_throw_error(NULL, "Cannot check dimension on a COM object");
return 0;
}

static void saproxy_property_delete(zend_object *object, zend_string *member, void **cache_slot)
{
php_error_docref(NULL, E_WARNING, "Cannot delete properties from a COM object");
zend_throw_error(NULL, "Cannot delete properties from a COM object");
}

static void saproxy_dimension_delete(zend_object *object, zval *offset)
{
php_error_docref(NULL, E_WARNING, "Cannot delete properties from a COM object");
zend_throw_error(NULL, "Cannot delete dimension from a COM object");
}

static HashTable *saproxy_properties_get(zend_object *object)
Expand Down
2 changes: 1 addition & 1 deletion ext/com_dotnet/com_typeinfo.c
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@ int php_com_process_typeinfo(ITypeInfo *typeinfo, HashTable *id_to_name, int pri

ret = 1;
} else {
zend_error(E_WARNING, "That's not a dispatchable interface!! type kind = %08x", attr->typekind);
zend_throw_error(NULL, "Type kind must be dispatchable, %08x given", attr->typekind);
}

ITypeInfo_ReleaseTypeAttr(typeinfo, attr);
Expand Down
8 changes: 4 additions & 4 deletions ext/com_dotnet/com_variant.c
Original file line number Diff line number Diff line change
Expand Up @@ -964,8 +964,8 @@ PHP_FUNCTION(variant_date_from_timestamp)
}

if (timestamp < 0) {
php_error_docref(NULL, E_WARNING, "Timestamp value must be a positive value.");
RETURN_FALSE;
zend_argument_value_error(1, "must be greater than or equal to 0");
RETURN_THROWS();
}

VariantInit(&res);
Expand All @@ -975,8 +975,8 @@ PHP_FUNCTION(variant_date_from_timestamp)

/* Invalid after 23:59:59, December 31, 3000, UTC */
if (!tmv) {
php_error_docref(NULL, E_WARNING, "Invalid timestamp " ZEND_LONG_FMT, timestamp);
RETURN_FALSE;
zend_argument_value_error(1, "must not go past 23:59:59, December 31, 3000, UTC");
RETURN_THROWS();
}

memset(&systime, 0, sizeof(systime));
Expand Down
12 changes: 8 additions & 4 deletions ext/com_dotnet/tests/bug72498.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ if (!extension_loaded("com_dotnet")) print "skip COM/.Net support not present";
<?php

$v1 = PHP_INT_MAX;
var_dump(variant_date_from_timestamp($v1));

try {
var_dump(variant_date_from_timestamp($v1));
} catch (\ValueError $e) {
echo $e->getMessage() . \PHP_EOL;
}
?>
--EXPECTF--
Warning: variant_date_from_timestamp(): Invalid timestamp %d in %sbug72498.php on line %d
bool(false)
--EXPECT--
variant_date_from_timestamp(): Argument #1 ($timestamp) must not go past 23:59:59, December 31, 3000, UTC