php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #38734 error message allocated even if not used
Submitted: 2006-09-06 18:15 UTC Modified: 2006-09-08 20:00 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: shire@php.net Assigned: iliaa (profile)
Status: Wont fix Package: Performance problem
PHP Version: 5.2.0RC3 OS: n/a
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2006-09-06 18:15 UTC] shire@php.net
Description:
------------
in the php_error_cb function the spprintf function is called as well as other code to allocate an error message even if this error message is never displayed due to logging levels or output settings.  (ie: error_reporting = E_ALL | ~E_NOTICE would cause all E_NOTICE messages to be allocated but not displayed).  This patch will short circuit the function call in these cases...

Index: main/main.c
===================================================================
RCS file: /repository/php-src/main/main.c,v
retrieving revision 1.640.2.23.2.13
diff -u -r1.640.2.23.2.13 main.c
--- main/main.c 17 Aug 2006 13:43:08 -0000      1.640.2.23.2.13
+++ main/main.c 6 Sep 2006 18:07:35 -0000
@@ -657,6 +657,14 @@
        int buffer_len, display;
        TSRMLS_FETCH();
 
+    /* Only go through this code if we are going to do something worth while... */
+    if ( PG(error_handling) == EH_NORMAL
+         && ( !(EG(error_reporting) & type) || !( PG(log_errors) || PG(display_errors) || (!module_initialized) ) )
+         && !( type & (E_ERROR | E_CORE | E_COMPILE_ERROR | E_USER_ERROR | E_PARSE | E_RECOVERABLE_ERROR) )
+       ) {
+        return;
+    } 
+
        buffer_len = vspprintf(&buffer, PG(log_errors_max_len), format, args);
 
        /* check for repeated errors to be ignored */


Reproduce code:
---------------
Set error_reporting to include E_NOTICE, use a test file like:

<?php echo $foo; // Produce E_NOTICE ?>



Expected result:
----------------
gdb trace shows the call into vpprintf...

Breakpoint 1, php_error_cb (type=8, error_filename=0x78def0 "/Users/shire/www/error.php", error_lineno=3, format=0x2443f8 "Undefined variable: %s", args=0xbfffec58 "??x") at /Users/shire/data/phpcvs-5.2/main/main.c:661
661         if ( PG(error_handling) == EH_NORMAL
(gdb) n
668             buffer_len = vspprintf(&buffer, PG(log_errors_max_len), format, args);


Actual result:
--------------
With the patch we skip this step when error_reporting does not include E_NOTICE...

Breakpoint 1, php_error_cb (type=8, error_filename=0x78def0 "/Users/shire/www/error.php", error_lineno=3, format=0x2443f8 "Undefined variable: %s", args=0xbfffec58 "??x") at /Users/shire/data/phpcvs-5.2/main/main.c:661
661         if ( PG(error_handling) == EH_NORMAL
(gdb) n
867     }
(gdb) n
zend_error (type=8, format=0x2443f8 "Undefined variable: %s") at /Users/shire/data/phpcvs-5.2/Zend/zend.c:942
942             if (!EG(user_error_handler)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-09-08 20:00 UTC] iliaa@php.net
I've reviewed the code path and it appears we cannot skip 
error message allocation code. 
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Thu Apr 15 03:01:24 2021 UTC