Skip to content

Commit 4516944

Browse files
kovsheninlavarou
authored andcommitted
fix(agent): Don't skip arguments when calling mysqli::real_connect
When one of the arguments in nr_php_mysqli_link_real_connect is null, the entire argument is skipped. This causes a fatal error when attempting to connect to a database through a Unix socket, without specifying a port number. This change ensures all arguments are passed on to real_connect in the correct order, including any nulls.
1 parent 787b87d commit 4516944

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

agent/php_mysqli.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -403,18 +403,22 @@ static nr_status_t nr_php_mysqli_link_real_connect(
403403
zval* retval = NULL;
404404

405405
#define ADD_IF_INT_SET(args, argc, value) \
406+
args[argc] = nr_php_zval_alloc(); \
406407
if (value) { \
407-
args[argc] = nr_php_zval_alloc(); \
408408
ZVAL_LONG(args[argc], value); \
409-
argc++; \
410-
}
409+
} else { \
410+
ZVAL_NULL(args[argc]); \
411+
} \
412+
argc++;
411413

412414
#define ADD_IF_STR_SET(args, argc, value) \
415+
args[argc] = nr_php_zval_alloc(); \
413416
if (value) { \
414-
args[argc] = nr_php_zval_alloc(); \
415417
nr_php_zval_str(args[argc], value); \
416-
argc++; \
417-
}
418+
} else { \
419+
ZVAL_NULL(args[argc]); \
420+
} \
421+
argc++;
418422

419423
ADD_IF_STR_SET(argv, argc,
420424
nr_php_mysqli_strip_persistent_prefix(metadata->host));

0 commit comments

Comments
 (0)