diff --git a/ext/config.w32 b/ext/config.w32 index affc729..a07a94e 100644 --- a/ext/config.w32 +++ b/ext/config.w32 @@ -1,7 +1,9 @@ +// vim:ft=javascript + ARG_ENABLE('opentelemetry', 'opentelemetry support', 'no'); if (PHP_OPENTELEMETRY != 'no') { AC_DEFINE('HAVE_OPENTELEMETRY', 1, 'opentelemetry support enabled'); - EXTENSION('opentelemetry', 'opentelemetry.c' 'otel_observer.c', null, '/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1'); + EXTENSION('opentelemetry', 'opentelemetry.c otel_observer.c', '/DZEND_ENABLE_STATIC_TSRMLS_CACHE=1'); } diff --git a/ext/otel_observer.c b/ext/otel_observer.c index 80cd3a7..d0130c8 100644 --- a/ext/otel_observer.c +++ b/ext/otel_observer.c @@ -195,10 +195,26 @@ static void log_invalid_message(char *msg, zval *scope, zval *function) { s = Z_STRVAL_P(scope); } char *f = Z_STRVAL_P(function); - char formatted[strlen(msg) + strlen(s) + strlen(f) + 1]; - snprintf(formatted, sizeof(formatted), msg, s, f); + // Calculate the size of the formatted message. + int formatted_size = strlen(msg) + strlen(s) + strlen(f) + 1; + + // Allocate a buffer for the formatted message. + char *formatted = malloc(formatted_size); + if (formatted == NULL) { + php_log_err("OpenTelemetry: Failed to allocate " + "memory for formatted message."); + return; + } + + // Format the message. + snprintf(formatted, formatted_size, msg, s, f); + + // Log the message. php_log_err(formatted); + + // Free the allocated memory. + free(formatted); } static void observer_begin(zend_execute_data *execute_data, zend_llist *hooks) { @@ -218,8 +234,8 @@ static void observer_begin(zend_execute_data *execute_data, zend_llist *hooks) { for (zend_llist_element *element = hooks->head; element; element = element->next) { - zend_fcall_info fci = {}; - zend_fcall_info_cache fcc = {}; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; zend_function *func = execute_data->func; // the observed function if (UNEXPECTED(zend_fcall_info_init((zval *)element->data, 0, &fci, &fcc, NULL, NULL) != SUCCESS)) { @@ -337,8 +353,8 @@ static void observer_end(zend_execute_data *execute_data, zval *retval, for (zend_llist_element *element = hooks->tail; element; element = element->prev) { - zend_fcall_info fci = {}; - zend_fcall_info_cache fcc = {}; + zend_fcall_info fci = empty_fcall_info; + zend_fcall_info_cache fcc = empty_fcall_info_cache; if (UNEXPECTED(zend_fcall_info_init((zval *)element->data, 0, &fci, &fcc, NULL, NULL) != SUCCESS)) { continue; diff --git a/ext/tests/005.phpt b/ext/tests/005.phpt index e0d49b6..b29febf 100644 --- a/ext/tests/005.phpt +++ b/ext/tests/005.phpt @@ -24,7 +24,7 @@ array(6) { [3]=> string(10) "helloWorld" [4]=> - string(%d) "%s/tests/005.php" + string(%d) "%s%etests%e005.php" [5]=> int(4) } @@ -44,7 +44,7 @@ array(8) { [5]=> string(10) "helloWorld" [6]=> - string(%d) "%s/tests/005.php" + string(%d) "%s%etests%e005.php" [7]=> int(4) } diff --git a/ext/tests/006.phpt b/ext/tests/006.phpt index 47a11fe..03ac877 100644 --- a/ext/tests/006.phpt +++ b/ext/tests/006.phpt @@ -26,7 +26,7 @@ array(6) { [3]=> string(10) "helloWorld" [4]=> - string(%d) "%s/tests/006.php" + string(%d) "%s%etests%e006.php" [5]=> int(4) } @@ -47,7 +47,7 @@ array(8) { [5]=> string(10) "helloWorld" [6]=> - string(%d) "%s/tests/006.php" + string(%d) "%s%etests%e006.php" [7]=> int(4) } diff --git a/ext/tests/invalid_post_callback_signature.phpt b/ext/tests/invalid_post_callback_signature.phpt index 830c20b..acef320 100644 --- a/ext/tests/invalid_post_callback_signature.phpt +++ b/ext/tests/invalid_post_callback_signature.phpt @@ -5,6 +5,8 @@ The invalid callback signature should not cause a fatal, so it is checked before is invalid, the callback will not be called. --EXTENSIONS-- opentelemetry +--XFAIL-- +Providing a post invalid callback signature causes segfault. The behaviour is currently disabled, so instead of a segfault a message is logged to error_log. --FILE--