diff --git a/ibase_query.c b/ibase_query.c index 3d8a46a..d8848d5 100644 --- a/ibase_query.c +++ b/ibase_query.c @@ -1901,6 +1901,10 @@ PHP_FUNCTION(ibase_free_result) } ib_result = (ibase_result *)zend_fetch_resource_ex(result_arg, LE_RESULT, le_result); + + _php_ibase_free_xsqlda(ib_result->out_sqlda); + efree(ib_result); + zend_list_delete(Z_RES_P(result_arg)); /* diff --git a/ibase_service.c b/ibase_service.c index c472163..69d4ae0 100644 --- a/ibase_service.c +++ b/ibase_service.c @@ -214,34 +214,60 @@ PHP_FUNCTION(ibase_delete_user) Connect to the service manager */ PHP_FUNCTION(ibase_service_attach) { - size_t hlen, ulen, plen, spb_len; + size_t hlen = 0, ulen = 0, plen = 0; ibase_service *svm; - char buf[128], *host, *user, *pass, *loc; + char buf[350], *host, *user, *pass; + char loc[128] = "service_mgr"; isc_svc_handle handle = 0; + unsigned short p = 0; RESET_ERRMSG; - if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "sss", + if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "|sss", &host, &hlen, &user, &ulen, &pass, &plen)) { RETURN_FALSE; } - /* construct the spb, hack the service name into it as well */ - spb_len = slprintf(buf, sizeof(buf), "%c%c%c%c%s%c%c%s" "%s:service_mgr", - isc_spb_version, isc_spb_current_version, isc_spb_user_name, (char)ulen, - user, isc_spb_password, (char)plen, pass, host); + if (ulen > 63) { + _php_ibase_module_error("Internal error: dba_username too long"); + RETURN_FALSE; + } - if (spb_len > sizeof(buf) || spb_len == -1) { - _php_ibase_module_error("Internal error: insufficient buffer space for SPB (%zd)", spb_len); + if (plen > 255) { + _php_ibase_module_error("Internal error: dba_password too long"); + RETURN_FALSE; + } + + // 13 = strlen(":service_mgr") + \0; + if (hlen + 13 > sizeof(loc)) { + _php_ibase_module_error("Internal error: insufficient buffer space for name of the service (%zd)", hlen + 13); RETURN_FALSE; } - spb_len -= hlen + 12; - loc = buf + spb_len; /* points to %s:service_mgr part */ + buf[p++] = isc_spb_version; + buf[p++] = isc_spb_current_version; + + if(ulen > 0){ + buf[p++] = isc_spb_user_name; + buf[p++] = (char)ulen; + memcpy(&buf[p], &user, ulen); + p += ulen; + } + + if(plen > 0){ + buf[p++] = isc_spb_password; + buf[p++] = (char)plen; + memcpy(&buf[p], &pass, plen); + p += plen; + } + + if(hlen > 0){ + slprintf(loc, sizeof(loc), "%s:service_mgr", host); + } /* attach to the service manager */ - if (isc_service_attach(IB_STATUS, 0, loc, &handle, (unsigned short)spb_len, buf)) { + if (isc_service_attach(IB_STATUS, 0, loc, &handle, p, buf)) { _php_ibase_error(); RETURN_FALSE; } diff --git a/interbase.c b/interbase.c index bbf8a24..5df9676 100644 --- a/interbase.c +++ b/interbase.c @@ -256,7 +256,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_ibase_delete_user, 0, 0, 3) ZEND_ARG_INFO(0, last_name) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_ibase_service_attach, 0, 0, 3) +ZEND_BEGIN_ARG_INFO_EX(arginfo_ibase_service_attach, 0, 0, 0) ZEND_ARG_INFO(0, host) ZEND_ARG_INFO(0, dba_username) ZEND_ARG_INFO(0, dba_password) @@ -711,12 +711,12 @@ static PHP_INI_DISP(php_ibase_password_displayer_cb) PUTS(" | "); \ } \ PUTS(str); \ - has_puts = true; \ + has_puts = 1; \ } while (0) static PHP_INI_DISP(php_ibase_trans_displayer) { - bool has_puts = false; + int has_puts = 0; char *value; if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) { @@ -1589,6 +1589,19 @@ PHP_FUNCTION(ibase_gen_id) RETURN_LONG((zend_long)result); } +void fbp_dump_buffer(int len, const unsigned char *buffer){ + int i; + for (i = 0; i < len; i++) { + if(buffer[i] < 31 || buffer[i] > 126) + php_printf("0x%02x ", buffer[i]); + else + php_printf("%c", buffer[i]); + } + if (i > 0) { + php_printf("\n"); + } +} + /* }}} */ #endif /* HAVE_IBASE */ diff --git a/php_ibase_includes.h b/php_ibase_includes.h index f162310..5e768f5 100644 --- a/php_ibase_includes.h +++ b/php_ibase_includes.h @@ -203,4 +203,6 @@ void php_ibase_service_minit(INIT_FUNC_ARGS); #define max(a,b) ((a)>(b)?(a):(b)) #endif +void fbp_dump_buffer(int len, const unsigned char *buffer); + #endif /* PHP_IBASE_INCLUDES_H */ diff --git a/tests/005.phpt b/tests/005.phpt index 382ea30..4cbff64 100644 --- a/tests/005.phpt +++ b/tests/005.phpt @@ -1,16 +1,21 @@ --TEST-- InterBase: transactions --SKIPIF-- - += 5.0)print 'skip: FB >= 5.0'; +?> --FILE-- --FILE-- --EXPECTF-- @@ -47,6 +46,3 @@ array(2) { } Warning: ibase_execute(): Statement expects 2 arguments, 1 given in %s on line %d - -Warning: ibase_fetch_assoc() expects parameter 1 to be resource, bool given in %s on line %d -NULL diff --git a/tests/datatype_int128.phpt b/tests/datatype_int128.phpt index 0cbdda5..e75d03e 100644 --- a/tests/datatype_int128.phpt +++ b/tests/datatype_int128.phpt @@ -3,25 +3,26 @@ Check for data type INT128 (Firebird 4.0 or above) --SKIPIF-- --FILE-- +--FILE-- + +--EXPECTF-- +object(stdClass)#1 (2) { + ["ID"]=> + int(1) + ["CLIENT_NAME"]=> + string(9) "Some name" +} \ No newline at end of file diff --git a/tests/skipif-php8-or-newer.inc b/tests/skipif-php8-or-newer.inc index bbf5c26..e3b7a55 100644 --- a/tests/skipif-php8-or-newer.inc +++ b/tests/skipif-php8-or-newer.inc @@ -1,5 +1,5 @@ = 8) { die('skip: This test verifies behavior that can only be observed in PHP versions < 8.0'); } -?> diff --git a/tests/skipif.inc b/tests/skipif.inc index c854f5b..4a95dd3 100644 --- a/tests/skipif.inc +++ b/tests/skipif.inc @@ -3,6 +3,5 @@ if (!extension_loaded("interbase")) print "skip interbase extension not available"; require("interbase.inc"); if(!@ibase_connect($test_base)){ - die("skip cannot connect"); + die("skip: cannot connect"); } -?>