Skip to content

Commit 16d7dcd

Browse files
Merge pull request #69 from mlazdans/master
Re-enable and fix some tests
2 parents 6e3d1ee + 313fe8b commit 16d7dcd

15 files changed

+149
-52
lines changed

ibase_query.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1901,6 +1901,10 @@ PHP_FUNCTION(ibase_free_result)
19011901
}
19021902

19031903
ib_result = (ibase_result *)zend_fetch_resource_ex(result_arg, LE_RESULT, le_result);
1904+
1905+
_php_ibase_free_xsqlda(ib_result->out_sqlda);
1906+
efree(ib_result);
1907+
19041908
zend_list_delete(Z_RES_P(result_arg));
19051909

19061910
/*

ibase_service.c

Lines changed: 38 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -214,34 +214,60 @@ PHP_FUNCTION(ibase_delete_user)
214214
Connect to the service manager */
215215
PHP_FUNCTION(ibase_service_attach)
216216
{
217-
size_t hlen, ulen, plen, spb_len;
217+
size_t hlen = 0, ulen = 0, plen = 0;
218218
ibase_service *svm;
219-
char buf[128], *host, *user, *pass, *loc;
219+
char buf[350], *host, *user, *pass;
220+
char loc[128] = "service_mgr";
220221
isc_svc_handle handle = 0;
222+
unsigned short p = 0;
221223

222224
RESET_ERRMSG;
223225

224-
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "sss",
226+
if (SUCCESS != zend_parse_parameters(ZEND_NUM_ARGS(), "|sss",
225227
&host, &hlen, &user, &ulen, &pass, &plen)) {
226228

227229
RETURN_FALSE;
228230
}
229231

230-
/* construct the spb, hack the service name into it as well */
231-
spb_len = slprintf(buf, sizeof(buf), "%c%c%c%c%s%c%c%s" "%s:service_mgr",
232-
isc_spb_version, isc_spb_current_version, isc_spb_user_name, (char)ulen,
233-
user, isc_spb_password, (char)plen, pass, host);
232+
if (ulen > 63) {
233+
_php_ibase_module_error("Internal error: dba_username too long");
234+
RETURN_FALSE;
235+
}
234236

235-
if (spb_len > sizeof(buf) || spb_len == -1) {
236-
_php_ibase_module_error("Internal error: insufficient buffer space for SPB (%zd)", spb_len);
237+
if (plen > 255) {
238+
_php_ibase_module_error("Internal error: dba_password too long");
239+
RETURN_FALSE;
240+
}
241+
242+
// 13 = strlen(":service_mgr") + \0;
243+
if (hlen + 13 > sizeof(loc)) {
244+
_php_ibase_module_error("Internal error: insufficient buffer space for name of the service (%zd)", hlen + 13);
237245
RETURN_FALSE;
238246
}
239247

240-
spb_len -= hlen + 12;
241-
loc = buf + spb_len; /* points to %s:service_mgr part */
248+
buf[p++] = isc_spb_version;
249+
buf[p++] = isc_spb_current_version;
250+
251+
if(ulen > 0){
252+
buf[p++] = isc_spb_user_name;
253+
buf[p++] = (char)ulen;
254+
memcpy(&buf[p], &user, ulen);
255+
p += ulen;
256+
}
257+
258+
if(plen > 0){
259+
buf[p++] = isc_spb_password;
260+
buf[p++] = (char)plen;
261+
memcpy(&buf[p], &pass, plen);
262+
p += plen;
263+
}
264+
265+
if(hlen > 0){
266+
slprintf(loc, sizeof(loc), "%s:service_mgr", host);
267+
}
242268

243269
/* attach to the service manager */
244-
if (isc_service_attach(IB_STATUS, 0, loc, &handle, (unsigned short)spb_len, buf)) {
270+
if (isc_service_attach(IB_STATUS, 0, loc, &handle, p, buf)) {
245271
_php_ibase_error();
246272
RETURN_FALSE;
247273
}

interbase.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_ibase_delete_user, 0, 0, 3)
256256
ZEND_ARG_INFO(0, last_name)
257257
ZEND_END_ARG_INFO()
258258

259-
ZEND_BEGIN_ARG_INFO_EX(arginfo_ibase_service_attach, 0, 0, 3)
259+
ZEND_BEGIN_ARG_INFO_EX(arginfo_ibase_service_attach, 0, 0, 0)
260260
ZEND_ARG_INFO(0, host)
261261
ZEND_ARG_INFO(0, dba_username)
262262
ZEND_ARG_INFO(0, dba_password)
@@ -711,12 +711,12 @@ static PHP_INI_DISP(php_ibase_password_displayer_cb)
711711
PUTS(" | "); \
712712
} \
713713
PUTS(str); \
714-
has_puts = true; \
714+
has_puts = 1; \
715715
} while (0)
716716

717717
static PHP_INI_DISP(php_ibase_trans_displayer)
718718
{
719-
bool has_puts = false;
719+
int has_puts = 0;
720720
char *value;
721721

722722
if (type == ZEND_INI_DISPLAY_ORIG && ini_entry->modified) {
@@ -1589,6 +1589,19 @@ PHP_FUNCTION(ibase_gen_id)
15891589
RETURN_LONG((zend_long)result);
15901590
}
15911591

1592+
void fbp_dump_buffer(int len, const unsigned char *buffer){
1593+
int i;
1594+
for (i = 0; i < len; i++) {
1595+
if(buffer[i] < 31 || buffer[i] > 126)
1596+
php_printf("0x%02x ", buffer[i]);
1597+
else
1598+
php_printf("%c", buffer[i]);
1599+
}
1600+
if (i > 0) {
1601+
php_printf("\n");
1602+
}
1603+
}
1604+
15921605
/* }}} */
15931606

15941607
#endif /* HAVE_IBASE */

php_ibase_includes.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,4 +203,6 @@ void php_ibase_service_minit(INIT_FUNC_ARGS);
203203
#define max(a,b) ((a)>(b)?(a):(b))
204204
#endif
205205

206+
void fbp_dump_buffer(int len, const unsigned char *buffer);
207+
206208
#endif /* PHP_IBASE_INCLUDES_H */

tests/005.phpt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,21 @@
11
--TEST--
22
InterBase: transactions
33
--SKIPIF--
4-
<?php die('skip: Broken test (Disabled until issue 41 is fixed)'); include("skipif.inc"); ?>
4+
<?php
5+
include("skipif.inc");
6+
if(get_fb_version() >= 5.0)print 'skip: FB >= 5.0';
7+
?>
58
--FILE--
69
<?php
710

11+
// See https://github.com/FirebirdSQL/php-firebird/issues/41
12+
813
require("interbase.inc");
914

1015
ibase_connect($test_base);
1116

12-
@ibase_query("create table test5 (i integer)");
13-
@ibase_query("delete from test5");
17+
ibase_query("create table test5 (i integer)");
18+
//ibase_query("delete from test5");
1419
ibase_close();
1520

1621

@@ -264,7 +269,7 @@ three rows in fourth transaction with deadlock
264269
2
265270
3
266271
4
267-
errmsg [lock conflict on no wait transaction deadlock %a]
272+
errmsg [%s]
268273
---
269274
three rows
270275
--- test5 ---

tests/bug45373.phpt

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,29 +5,28 @@ Bug #45373 (php crash on query with errors in params)
55
include("skipif.inc");
66
// See GitHub issue 44
77
// https://github.com/FirebirdSQL/php-firebird/issues/44
8-
include("skipif-php8-or-newer.inc");
98
?>
109
--FILE--
1110
<?php
1211

13-
require("interbase.inc");
12+
require("interbase.inc");
1413

15-
$db = ibase_connect($test_base);
14+
$db = ibase_connect($test_base);
1615

16+
$q = ibase_prepare($db, "SELECT * FROM TEST1 WHERE I = ? AND C = ?");
17+
$r = ibase_execute($q, 1, 'test table not created with isql');
18+
var_dump(ibase_fetch_assoc($r));
19+
ibase_free_result($r);
1720

18-
$sql = "select * from test1 where i = ? and c = ?";
21+
// MUST run with error_reporting & E_NOTICE to generate Notice:
22+
$r = ibase_execute($q, 1, 'test table not created with isql', 1);
23+
var_dump(ibase_fetch_assoc($r));
24+
ibase_free_result($r);
1925

20-
$q = ibase_prepare($db, $sql);
21-
$r = ibase_execute($q, 1, 'test table not created with isql');
22-
var_dump(ibase_fetch_assoc($r));
23-
ibase_free_result($r);
24-
25-
$r = ibase_execute($q, 1, 'test table not created with isql', 1);
26-
var_dump(ibase_fetch_assoc($r));
27-
ibase_free_result($r);
28-
29-
$r = ibase_execute($q, 1);
30-
var_dump(ibase_fetch_assoc($r));
26+
// Enforcing function parameters became more stricter in latest versions of PHP
27+
if($r = ibase_execute($q, 1)) {
28+
var_dump(ibase_fetch_assoc($r));
29+
}
3130

3231
?>
3332
--EXPECTF--
@@ -47,6 +46,3 @@ array(2) {
4746
}
4847

4948
Warning: ibase_execute(): Statement expects 2 arguments, 1 given in %s on line %d
50-
51-
Warning: ibase_fetch_assoc() expects parameter 1 to be resource, bool given in %s on line %d
52-
NULL

tests/datatype_int128.phpt

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,26 @@ Check for data type INT128 (Firebird 4.0 or above)
33
--SKIPIF--
44
<?php
55
include("skipif.inc");
6+
if(get_fb_version() < 4.0)print "skip FB < 4.0";
67
?>
78
--FILE--
89
<?php
910

10-
require("interbase.inc");
11+
require("interbase.inc");
1112

12-
$db = ibase_connect($test_base);
13+
$db = ibase_connect($test_base);
1314

1415
ibase_query(
15-
"create table test_dt (
16-
v_int128 int128 not null
16+
"CREATE TABLE TEST_DT (
17+
V_INT128 INT128 NOT NULL
1718
)");
1819
ibase_commit();
1920

20-
ibase_query("insert into test_dt (v_int128) values (1234)");
21-
ibase_query("insert into test_dt (v_int128) values (-170141183460469231731687303715884105728)");
22-
ibase_query("insert into test_dt (v_int128) values (170141183460469231731687303715884105727)");
21+
ibase_query("INSERT INTO TEST_DT (V_INT128) VALUES (1234)");
22+
ibase_query("INSERT INTO TEST_DT (V_INT128) VALUES (-170141183460469231731687303715884105728)");
23+
ibase_query("INSERT INTO TEST_DT (V_INT128) VALUES (170141183460469231731687303715884105727)");
2324

24-
$sql = 'select * from test_dt';
25+
$sql = 'SELECT * FROM TEST_DT';
2526
$query = ibase_query($sql);
2627
while(($row = ibase_fetch_assoc($query))) {
2728
var_dump($row);

tests/ibase_drop_db_001.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ ibase_drop_db(): Basic test
77

88
require("config.inc");
99

10-
unlink($file = tempnam('/tmp',"php_ibase_test"));
10+
unlink($file = tempnam(sys_get_temp_dir(),"php_ibase_test"));
1111
if(!empty($host))$file = "$host:$file";
1212

1313
$db = ibase_query(IBASE_CREATE,

tests/ibase_drop_db_002.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ include("skipif-php8-or-newer.inc");
1010

1111
require("config.inc");
1212

13-
unlink($file = tempnam('/tmp',"php_ibase_test"));
13+
unlink($file = tempnam(sys_get_temp_dir(),"php_ibase_test"));
1414

1515
$db = ibase_query(IBASE_CREATE,
1616
sprintf("CREATE SCHEMA '%s' USER '%s' PASSWORD '%s' DEFAULT CHARACTER SET %s",$file,

tests/ibase_drop_db_003.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ include("skipif-php7-or-older.inc");
1010

1111
require("config.inc");
1212

13-
unlink($file = tempnam('/tmp',"php_ibase_test"));
13+
unlink($file = tempnam(sys_get_temp_dir(),"php_ibase_test"));
1414
if(!empty($host))$file = "$host:$file";
1515

1616
$db = ibase_query(IBASE_CREATE,

0 commit comments

Comments
 (0)