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

- Thread: https://externals.io/message/9168
- Original archive: https://news-web.php.net/php.internals/9168
- Started by Per Jessen on 2004-04-15T10:29:12+00:00
- Messages: 5
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #9168 — Per Jessen — 2004-04-15T10:29:12+00:00

URL: https://externals.io/message/9168#9168

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

---

## #9169 — Per Jessen — 2004-04-15T10:44:20+00:00

URL: https://externals.io/message/9168#9169 · In reply to: #9168

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

---

## #9170 — Antony Dovgal — 2004-04-15T10:57:16+00:00

URL: https://externals.io/message/9168#9170 · In reply to: #9169

On Thu, 15 Apr 2004 12:44:20 +0200
Per Jessen <per@computer.org> wrote:

> Per Jessen wrote:
> 
> > […]
> 
> 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

---

## #9172 — Derick Rethans — 2004-04-15T11:10:56+00:00

URL: https://externals.io/message/9168#9172 · In reply to: #9168

> 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

---

## #9175 — Per Jessen — 2004-04-15T11:38:23+00:00

URL: https://externals.io/message/9168#9175 · In reply to: #9172

Derick Rethans wrote:

> 
> 
> > […]
> 
> 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
