Seg fault in PHP (FormsAPI)? Can you reproduce?
Hi everyone, I've just run into a segfault situation during development of a form element. Basically, all I changed from a working system was add a new form element and accidentally left something off one of the child element definitions. Here is a code snippet you can drop into a module and see if you can reproduce it. PHP Version: 4.3.10-16 System: Debian Sarge Kernel: 2.6.8-3-k7 function maillist_elements() { $type['listadmin'] = array('#input' => TRUE, '#process' => array('expand_listadmin' => array())); return $type; } function expand_listadmin($element) { $options = array('blah' => 'blah'); $element['list'] = array('#type' => 'select', '#options' => $options, '#value' => $element['#value']['list']); // $element['or'] = array('#type' => 'markup', '<span style="padding: 0 20px; text-weight: bold;">OR</span>'); $element['or'] = array('#type' => 'markup', '#value' => '<span style="padding: 0 20px; text-weight: bold;">OR</span>'); $element['text'] = array('#type' => 'textfield', '#size' => 50, '#maxlength' => 256, '#value' => $element['#value']['text']); $element['#tree'] = TRUE; return $element; } function theme_listadmin($element) { $output = '<div class="container-inline">' . $element['#children'] . '</div>'; return theme('form_element', $element['#title'], $output, $element['#description'], $element['#id'], $element['#required'], form_get_error($element)); } The commented out line is the one that is causing the segfault. The line below is the working line. It could be the forms API code ends up in an infinite loop over this little fella and, if so, i'm happy to fix it. Just need someone to reconfirm this happens (especially in another version of PHP). Cheers, -- Sammy Spets Synerger Pty Ltd http://www.synerger.com/
It could be the forms API code ends up in an infinite loop over this little fella and, if so, i'm happy to fix it. Just need someone to reconfirm this happens (especially in another version of PHP).
I have had two instances of segfaults in PHP, though unrelated to FormsAPI. The first one I was able to track to an older version (Feb?) of the og_forum contrib module, in the function og_forum_db_rewrite_sql(). For some reason it was getting called again and again until PHP segfaulted. This happens with PHP 4.4. The second one was when I switched from Mandriva to Ubuntu, and from 4.3.x to 4.4. It would only happen when drupal was installed under a subdirectory, so I suspect a mod_rewrite bug, which someone reported on SuSE as well somewhere on Drupal.org.
On XAMPP - Apache + PHP 5.1 only this error occurs when I uncomment the faulty line... Fatal error: Cannot create references to/from string offsets nor overloaded objects in D:\htdocs\drupal7\includes\form.inc on line 341 cheers, tadej Sammy Spets pravi:
Hi everyone,
I've just run into a segfault situation during development of a form element. Basically, all I changed from a working system was add a new form element and accidentally left something off one of the child element definitions. Here is a code snippet you can drop into a module and see if you can reproduce it.
PHP Version: 4.3.10-16 System: Debian Sarge Kernel: 2.6.8-3-k7
function maillist_elements() { $type['listadmin'] = array('#input' => TRUE, '#process' => array('expand_listadmin' => array())); return $type; }
function expand_listadmin($element) { $options = array('blah' => 'blah'); $element['list'] = array('#type' => 'select', '#options' => $options, '#value' => $element['#value']['list']); // $element['or'] = array('#type' => 'markup', '<span style="padding: 0 20px; text-weight: bold;">OR</span>'); $element['or'] = array('#type' => 'markup', '#value' => '<span style="padding: 0 20px; text-weight: bold;">OR</span>'); $element['text'] = array('#type' => 'textfield', '#size' => 50, '#maxlength' => 256, '#value' => $element['#value']['text']); $element['#tree'] = TRUE; return $element; }
function theme_listadmin($element) { $output = '<div class="container-inline">' . $element['#children'] . '</div>'; return theme('form_element', $element['#title'], $output, $element['#description'], $element['#id'], $element['#required'], form_get_error($element)); }
The commented out line is the one that is causing the segfault. The line below is the working line.
It could be the forms API code ends up in an infinite loop over this little fella and, if so, i'm happy to fix it. Just need someone to reconfirm this happens (especially in another version of PHP).
Cheers,
Thanks Tadej! Interesting. Still looking for more examples. Cheers, -- Sammy Spets Synerger Pty Ltd http://www.synerger.com/ On 27-Apr-06 08:52, Tadej Ba??a wrote:
On XAMPP - Apache + PHP 5.1 only this error occurs when I uncomment the faulty line...
Fatal error: Cannot create references to/from string offsets nor overloaded objects in D:\htdocs\drupal7\includes\form.inc on line 341
cheers, tadej
Sammy Spets pravi:
Hi everyone,
I've just run into a segfault situation during development of a form element. Basically, all I changed from a working system was add a new form element and accidentally left something off one of the child element definitions. Here is a code snippet you can drop into a module and see if you can reproduce it.
PHP Version: 4.3.10-16 System: Debian Sarge Kernel: 2.6.8-3-k7
function maillist_elements() { $type['listadmin'] = array('#input' => TRUE, '#process' => array('expand_listadmin' => array())); return $type; }
function expand_listadmin($element) { $options = array('blah' => 'blah'); $element['list'] = array('#type' => 'select', '#options' => $options, '#value' => $element['#value']['list']); // $element['or'] = array('#type' => 'markup', '<span style="padding: 0 20px; text-weight: bold;">OR</span>'); $element['or'] = array('#type' => 'markup', '#value' => '<span style="padding: 0 20px; text-weight: bold;">OR</span>'); $element['text'] = array('#type' => 'textfield', '#size' => 50, '#maxlength' => 256, '#value' => $element['#value']['text']); $element['#tree'] = TRUE; return $element; }
function theme_listadmin($element) { $output = '<div class="container-inline">' . $element['#children'] . '</div>'; return theme('form_element', $element['#title'], $output, $element['#description'], $element['#id'], $element['#required'], form_get_error($element)); }
The commented out line is the one that is causing the segfault. The line below is the working line.
It could be the forms API code ends up in an infinite loop over this little fella and, if so, i'm happy to fix it. Just need someone to reconfirm this happens (especially in another version of PHP).
Cheers,
Sammy Spets wrote:
Hi everyone,
I've just run into a segfault situation during development of a form element. Basically, all I changed from a working system was add a new form element and accidentally left something off one of the child element definitions. Here is a code snippet you can drop into a module and see if you can reproduce it.
I am pretty sure I could. Your code omitted the key for the form element. form API doesn't like this (or wrong keys for that matter). No idea why php crashes because of this, but in any way: Your code is broken, fix it and it wont crash anymore. Cheers, Gerhard
Yeah I understand that. I'm interested in finding out why :) Also, isn't it better if form API handles this gracefully? -- Sammy Spets Synerger Pty Ltd http://www.synerger.com/ On 27-Apr-06 12:20, Gerhard Killesreiter wrote:
Sammy Spets wrote:
Hi everyone,
I've just run into a segfault situation during development of a form element. Basically, all I changed from a working system was add a new form element and accidentally left something off one of the child element definitions. Here is a code snippet you can drop into a module and see if you can reproduce it.
I am pretty sure I could. Your code omitted the key for the form element. form API doesn't like this (or wrong keys for that matter). No idea why php crashes because of this, but in any way: Your code is broken, fix it and it wont crash anymore.
Cheers, Gerhard
Actually, no. Gracefully handling is for things that can legitimately go wrong in production. A missing form element key will never make it to production no matter what. It might as well blow up to get your attention right away. On 4/27/06, Sammy Spets <sammys-drupal@synerger.com> wrote:
Yeah I understand that. I'm interested in finding out why :) Also, isn't it better if form API handles this gracefully?
Hi Sammy, On 27 Apr 2006, at 13:10, Sammy Spets wrote:
Yeah I understand that. I'm interested in finding out why :) Also, isn't it better if form API handles this gracefully?
PHP code should never cause a segfault. Looks like your code triggered a bug in the PHP engine (and not a bug in Drupal). Best to upgrade your PHP installation and -- if the problem remains -- to file a bug report at the PHP website. They'll be able to figure out what is causing the problem. -- Dries Buytaert :: http://www.buytaert.net/
Dries Buytaert wrote:
Hi Sammy,
On 27 Apr 2006, at 13:10, Sammy Spets wrote:
Yeah I understand that. I'm interested in finding out why :) Also, isn't it better if form API handles this gracefully?
PHP code should never cause a segfault. Looks like your code triggered a bug in the PHP engine (and not a bug in Drupal).
Recursive assignments in loops (often from older, badly-ported routines) will almost always cause a segfault unless you have xdebug to trap them at a user-defined limit. Seems PHP4 is lacking generally in detecting recursions before they KO a server process. og/contrib in particular had lots, but they're being worked through. -- ------------------------------------------- John Handelaar E john@handelaar.org T +353 21 427 9033 M +353 85 748 3790 http://handelaar.org ------------------------------------------- Work in progress: http://dev.vocalvoter.com -------------------------------------------
participants (7)
-
Dries Buytaert -
Earl Dunovant -
Gerhard Killesreiter -
John Handelaar -
Khalid B -
Sammy Spets -
Tadej Baša