what is the reasonable thing to with a segfault in php?

php.internals

Per Jessen

22 years ago
Hi, I've got a situation where a seemingly innocent statement produces a segfault. I've tried reducing it to a single reproducable testcase, but without success. The problem is however solidly reproducable in the context in which it occurs. I'm *certain* it is caused by a mistake in *my* code, but I feel it isn't exactly appropriate for php to segfault because of a user error? Very briefly, this is an excerpt where the segfault occurs: <h2><?php print $_SESSION['customers'][$customer]; ?></h2> <?php $q="<longish SELECT query>"; $result=mysql_query( $q ) or die("mysql:".mysql_error()); $main_address=mysql_fetch_array( $result, MYSQL_ASSOC ); $q="<longish SELECT query>"; $result=mysql_query( $q ) or die(mysql_error()); $billing_address=mysql_fetch_array( $result, MYSQL_ASSOC ); $q="<longish SELECT query>"; $result=mysql_query( $q ) or die(mysql_error()); $technical_address=mysql_fetch_array( $result, MYSQL_ASSOC ); $editmain=strcasecmp($_REQUEST['contact'],"main")==0; //$editbilling=strcasecmp($_REQUEST['contact'],"billing")==0; //$edittechnical=strcasecmp($_REQUEST['contact'],"technical")==0; ?> If I uncomment either of the last 2 commented-out statements, I get a segfault. I'm using php 4.3.4 and apache 2.0.49 on linux 2.4.24. mysql is 4.0.15. /Per Jessen, Zurich

Per Jessen

22 years ago
Per Jessen wrote:
> > $editmain=strcasecmp($_REQUEST['contact'],"main")==0; > //$editbilling=strcasecmp($_REQUEST['contact'],"billing")==0; > //$edittechnical=strcasecmp($_REQUEST['contact'],"technical")==0; >
OK, I've now guarded the above with : if ( isset($_REQUEST['contact']) ) { $editmain=strcmp($_REQUEST['contact'],"main")==0; $editbilling=strcmp($_REQUEST['contact'],"billing")==0; $edittechnical=strcasecmp($_REQUEST['contact'],"technical")==0; } and the segfault is gone. Still, a segfault just because I'm using an unset global? And why only on the 2nd or later statement? /Per Jessen, Zurich

Antony Dovgal

22 years ago
On Thu, 15 Apr 2004 12:44:20 +0200 Per Jessen <per@computer.org> wrote:
> Per Jessen wrote: > > > > > $editmain=strcasecmp($_REQUEST['contact'],"main")==0; > > //$editbilling=strcasecmp($_REQUEST['contact'],"billing")==0; > > //$edittechnical=strcasecmp($_REQUEST['contact'],"technical")==0; > > > > OK, > I've now guarded the above with : > > if ( isset($_REQUEST['contact']) ) > { > $editmain=strcmp($_REQUEST['contact'],"main")==0; > $editbilling=strcmp($_REQUEST['contact'],"billing")==0; > $edittechnical=strcasecmp($_REQUEST['contact'],"technical")==0; > } > > and the segfault is gone. Still, a segfault just because I'm using an unset > global? And why only on the 2nd or later statement? >
Read this first: http://bugs.php.net/how-to-report.php Try a CVS snapshot and generate a backtrace - this would help more than your code. --- WBR, Antony Dovgal aka tony2001 tony2001@phpclub.net || antony@dovgal.com

Derick Rethans

22 years ago
On Thu, 15 Apr 2004, Per Jessen wrote:
> I'm *certain* it is caused by a mistake in *my* code, but I feel it isn't > exactly appropriate for php to segfault because of a user error?
Right, it's not supposed to do so. Please make a backtrace of the segfault (with gdb), or try with valgrind to see what goes wrong. Derick

Per Jessen

22 years ago
Derick Rethans wrote:
> On Thu, 15 Apr 2004, Per Jessen wrote: > >> I'm *certain* it is caused by a mistake in *my* code, but I feel it isn't >> exactly appropriate for php to segfault because of a user error? > > Right, it's not supposed to do so. Please make a backtrace of the > segfault (with gdb), or try with valgrind to see what goes wrong.
I'll try with a CVS snapshot later, but for now I've opened http://bugs.php.net/bug.php?id=28006 and added the backtrace from my current php (4.3.4). /Per Jessen, Zurich