Hello,

First, I want to apologize in advance if this should be the wrong list for
this. Please just point me to the correct list in this case.

As noted in the documentation of the function trigger_error
(http://www.php.net/trigger_error), an error message is limited to 1024
characters. It gets truncated if it is longer.

In the PHP web application i currently develop, this can sometimes be pretty
annoying, because i use trigger_error to report error messages i get when
executing SQL queries to a custom error handler that mails me all those
errors. This error message sometimes contain SQL statements that are far
longer than 1024 characters. They get truncated, and i can not see the real
reason of the error then.

The patch i attached increases this limit by continually increasing the
buffer that should hold the error message, until the error message does not
fill up the entire buffer any more.

The patch is against 4.3.4RC1, but should still seemlessly apply to the 4.3
branch in CVS.
--- php-4.3.4RC1.orig/Zend/zend.c	2003-09-22 06:22:06.000000000 +0200
+++ php-4.3.4RC1/Zend/zend.c	2003-10-02 13:35:38.000000000 +0200
@@ -705,6 +705,7 @@
 	char *error_filename;
 	uint error_lineno;
 	zval *orig_user_error_handler;
+	uint errmsg_buffer_size;
 	TSRMLS_FETCH();
 
 	/* Obtain relevant filename and lineno */
@@ -766,22 +767,31 @@
 			ALLOC_INIT_ZVAL(z_error_filename);
 			ALLOC_INIT_ZVAL(z_error_lineno);
 			ALLOC_INIT_ZVAL(z_context);
-			z_error_message->value.str.val = (char *) emalloc(ZEND_ERROR_BUFFER_SIZE);
 
+			errmsg_buffer_size = 0;
+			z_error_message->value.str.val = NULL;
+
+			do {
+				errmsg_buffer_size += ZEND_ERROR_BUFFER_SIZE;
+				if (NULL != z_error_message->value.str.val)
+					efree(z_error_message->value.str.val);
+				z_error_message->value.str.val = (char *) emalloc(errmsg_buffer_size);
 #ifdef HAVE_VSNPRINTF
-			vsnprintf(z_error_message->value.str.val, ZEND_ERROR_BUFFER_SIZE, format, args);
-			/* this MUST be revisited, but for now handle ALL implementation 
-			 * out there correct. Since this is inside an error handler the 
-			 * performance loss by strlne is irrelevant. */
-			z_error_message->value.str.val[ZEND_ERROR_BUFFER_SIZE - 1] = '\0';
-			z_error_message->value.str.len = strlen(z_error_message->value.str.val);
+				vsnprintf(z_error_message->value.str.val, errmsg_buffer_size, format, args);
+				/* this MUST be revisited, but for now handle ALL implementation 
+				 * out there correct. Since this is inside an error handler the 
+				 * performance loss by strlen is irrelevant. */
+				z_error_message->value.str.val[errmsg_buffer_size - 1] = '\0';
+				z_error_message->value.str.len = strlen(z_error_message->value.str.val);
 #else
-			strncpy(z_error_message->value.str.val, format, ZEND_ERROR_BUFFER_SIZE);
-			z_error_message->value.str.val[ZEND_ERROR_BUFFER_SIZE - 1] = '\0';
-			z_error_message->value.str.len = strlen(z_error_message->value.str.val);
-			/* This is risky... */
-			/* z_error_message->value.str.len = vsprintf(z_error_message->value.str.val, format, args); */
+				strncpy(z_error_message->value.str.val, format, errmsg_buffer_size);
+				z_error_message->value.str.val[errmsg_buffer_size - 1] = '\0';
+				z_error_message->value.str.len = strlen(z_error_message->value.str.val);
+				/* This is risky... */
+				/* z_error_message->value.str.len = vsprintf(z_error_message->value.str.val, format, args); */
 #endif
+			} while (z_error_message->value.str.len >= (errmsg_buffer_size - 1));
+
 			z_error_message->type = IS_STRING;
 
 			z_error_type->value.lval = type;

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to