Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:4665 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 27831 invoked by uid 1010); 3 Oct 2003 16:30:33 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 27785 invoked by uid 1007); 3 Oct 2003 16:30:33 -0000 Message-ID: <20031003163033.27783.qmail@pb1.pair.com> To: internals@lists.php.net Date: Fri, 03 Oct 2003 18:34:13 +0200 Lines: 83 Organization: Ecommerce.Com User-Agent: KNode/0.7.2 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="nextPart1439121.yyTOuA2StQ" Content-Transfer-Encoding: 7Bit X-Posted-By: 213.208.20.19 Subject: PATCH: error message length limit From: mike@ecommerce.com (Aigner Michael Franz) --nextPart1439121.yyTOuA2StQ Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8Bit 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. --nextPart1439121.yyTOuA2StQ Content-Type: text/x-diff; name="php-4.3.4RC1-errmsg-len.patch" Content-Transfer-Encoding: 8Bit Content-Disposition: attachment; filename="php-4.3.4RC1-errmsg-len.patch" --- 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; --nextPart1439121.yyTOuA2StQ--