# segmentation fault when passing arguments by reference or importing global variables

- Thread: https://externals.io/message/15137
- Original archive: https://news-web.php.net/php.internals/15137
- Started by Martin Sarsale on 2005-02-21T18:21:24+00:00
- Messages: 6
- 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

---

## #15137 — Martin Sarsale — 2005-02-21T18:21:24+00:00

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

Dear All:
Im having some weird problems here. We're working on a big project, 
based on PHP and we found that some code that used to work, is doing 
very strange things.
Im getting segfaults in some parts of the code, for example:
function XXX(&$databaseConnection, $xxx) {
or
global $xxx;

At first, I was getting segfaults with very little info. After I 
installed php-mmturck, the file, line and opcode where the error happen 
is reported in apache error log:


[4577] MMCACHE: PHP crashed on opline 1 of XXX() at 
/var/www/xxx/XXX.class.php:58
[Mon Feb 21 15:16:02 2005] [notice] child pid 4577 exit signal 
Segmentation fault (11)

Line 58 has:
function XXX(&$databaseConnection, $_xxx) {

Im using PHP 4.3.10-2 (debian gnu/linux testing) but I can recompile it 
or test another version, if you think it's important.

Thanks in advance :)


-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 266.2.0 - Release Date: 2/21/2005

---

## #15138 — Derick Rethans — 2005-02-21T18:38:42+00:00

URL: https://externals.io/message/15137#15138 · In reply to: #15137

> Im having some weird problems here. We're working on a big project,
> based on PHP and we found that some code that used to work, is doing
> very strange things.

I've been noticing the same things, and still trying to figure out where
it happens. It has most likely to do with returning-by-reference in the
wrong places.

It's also not very easy to reproduce the problem - I already spoke to
several people including the guys that wrote zend, but they don't seem
interested in fixing it for PHP 4.

regards,
Derick

-- 
Derick Rethans
http://derickrethans.nl | http://ez.no | http://xdebug.org

---

## #15139 — Martin Sarsale — 2005-02-21T18:56:34+00:00

URL: https://externals.io/message/15137#15139 · In reply to: #15138

Derick Rethans wrote:

> I've been noticing the same things, and still trying to figure out where
> it happens. It has most likely to do with returning-by-reference in the
> wrong places.

What do you mean with returning by reference in the wrong places? could 
you give me an example?


-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 266.2.0 - Release Date: 2/21/2005

---

## #15141 — Michael Walter — 2005-02-22T02:21:16+00:00

URL: https://externals.io/message/15137#15141 · In reply to: #15139

I've as well experienced this problem several times (in a medium-size
code base).

By returning-by-reference in the wrong places, do you mean something like
  function foo() { return 10;}
  $bar=&foo();
I'm pretty convinced that even with "correct" (in that respect) code
the crash still occurs.

Michael


On Mon, 21 Feb 2005 15:56:34 -0300, Martin Sarsale
<martin.sarsale@tnsweb.com> wrote:
> Derick Rethans wrote:
> 
> > […]
> 
> What do you mean with returning by reference in the wrong places? could
> you give me an example?
> 
> 
> --
> No virus found in this outgoing message.
> Checked by AVG Anti-Virus.
> Version: 7.0.300 / Virus Database: 266.2.0 - Release Date: 2/21/2005

---

## #15142 — Todd Ruth — 2005-02-22T03:37:26+00:00

URL: https://externals.io/message/15137#15142 · In reply to: #15141

Ahh... my favorite topic.  I think I covered all the cases
our company has hit in the following message to this list:

http://marc.theaimsgroup.com/?l=php-dev&m=109631219107237&w=2

I've never seen a response as to whether there is hope for fixes
of these problems.  I ended up hacking at an already very ugly
p*rl script (a language that shouldn't be mentioned on this list)
to look for attempts to use non-referencable things as references.
Unfortunately, not only is it in the language which must not be
named, but it also makes some assumptions about the code based on
company standards.  I keep my fingers crossed that someone with
appropriate skills will write a tool to do the check right.  The
problems can be painful to find.  e.g.

function g() {
   return NULL;
}
function h(&$x) {
   $x = 5;
}
h(g());

can cause php to crash.  (Don't bother trying to reproduce it
though.  It only causes a crash with a _lot_ of other php code
with it to make things interesting.)

Good luck!

- Todd


> I've as well experienced this problem several times (in a medium-size
> code base).
> 
> By returning-by-reference in the wrong places, do you mean something like
>   function foo() { return 10;}
>   $bar=&foo();
> I'm pretty convinced that even with "correct" (in that respect) code
> the crash still occurs.
> 
> Michael
> 
> 
> On Mon, 21 Feb 2005 15:56:34 -0300, Martin Sarsale
> <martin.sarsale@tnsweb.com> wrote:
> > […]

---

## #15149 — Martin Sarsale — 2005-02-22T13:59:46+00:00

URL: https://externals.io/message/15137#15149 · In reply to: #15138

> I've been noticing the same things, and still trying to figure out where
> it happens. It has most likely to do with returning-by-reference in the
> wrong places.
> 
> It's also not very easy to reproduce the problem - I already spoke to
> several people including the guys that wrote zend, but they don't seem
> interested in fixing it for PHP 4.

I've downgraded to PHP 4.3.5 and it works ok. I tried 4.3.6 ... 
4.3.11-dev with no luck.
Now, I'll have to figure out how to apply security patches for later 
versions to 4.3.5

thanks


-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 266.2.0 - Release Date: 2/21/2005
