Thread: PostgreSQL / PHP Overrun Error

PostgreSQL / PHP Overrun Error

From
"Mike Rogers"
Date:
I have just upgraded to the new PostgreSQL 7.1.3 (from 7.0.3) and have been
experiencing a pretty serious problem:
    On one particular page, in what seems to be completely random instances,
I get buffer overruns and either 0-rows or a crashed apache child.  Turning
on PHP's --enable-debug, I receive the following:


[Wed Sep 26 06:21:12 2001]  Script:  '/path/to/script.php'
---------------------------------------
pgsql.c(167) : Block 0x086A6DF8 status:
Beginning:      Overrun (magic=0x00000000, expected=0x7312F8DC)
      End:      Unknown
---------------------------------------

Sometimes it will actually crash mid-way (probably overwrote some valuable
code):
---------------------------------------
pgsql.c(167) : Block 0x08684290 status:
Beginning:      Overrun (magic=0x0000111A, expected=0x7312F8DC)
[Wed Sep 26 09:22:46 2001] [notice] child pid 8710 exit signal Segmentation
fault (11)

This problem is of great concern to me and I have been working for days
trying to debug it myself and find other reports, with little success.  The
line it claims to be failing on is PHP's ext/pgsql/pgsql.c on line 167 (by
what this claims) which is the following function [the
efree(PGG(last_notice)) line].

static void
_notice_handler(void *arg, const char *message)
{
        PGLS_FETCH();

        if (! PGG(ignore_notices)) {
                php_log_err((char *) message);
                if (PGG(last_notice) != NULL) {
                        efree(PGG(last_notice));
                }
                PGG(last_notice) = estrdup(message);
        }
}


Can anyone provide further input as to why this is causing problems?  The
PHP code works sometimes and not others, and it seems to be only that one
script, so I do not believe it to be a hardware issue.

Any thoughts?  I can provide any further system information if needed.  I
have tried recompiling pgsql, php and apache with different optimizations
[including none at all and debug mode on as i have now] with little change
in the result.

Thanks in advance;
--
Mike

cc: pgsql-hackers; pgsql-php; pgsql_bugs

Re: PostgreSQL / PHP Overrun Error

From
Tom Lane
Date:
"Mike Rogers" <temp6453@hotmail.com> writes:
> This problem is of great concern to me and I have been working for days
> trying to debug it myself and find other reports, with little success.  The
> line it claims to be failing on is PHP's ext/pgsql/pgsql.c on line 167 (by
> what this claims) which is the following function [the
> efree(PGG(last_notice)) line].

This isn't our code, so you'd likely have better luck complaining on
some PHP-related list.  But it looks to me like this code is simply
trying to free any previous notice message before it stores the new
one into PGG(last_notice) (whatever the heck that is).  I'm guessing
that that pointer is uninitialized or has been clobbered somehow.

            regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org




Re: PostgreSQL / PHP Overrun Error

From
"Mike Rogers"
Date:
Well it really isn't your code (true), but the only thing that is changed is
the 7.0-7.1-  Was a data length changed on the return or something that
could affect this?
--
Mike

----- Original Message -----
From: "Tom Lane" <tgl@sss.pgh.pa.us>
To: "Mike Rogers" <temp6453@hotmail.com>
Cc: <pgsql-hackers@postgresql.org>; <pgsql-php@postgresql.org>;
<pgsql-bugs@postgresql.org>
Sent: Wednesday, September 26, 2001 1:23 PM
Subject: Re: [BUGS] PostgreSQL / PHP Overrun Error


> "Mike Rogers" <temp6453@hotmail.com> writes:
> > This problem is of great concern to me and I have been working for days
> > trying to debug it myself and find other reports, with little success.
The
> > line it claims to be failing on is PHP's ext/pgsql/pgsql.c on line 167
(by
> > what this claims) which is the following function [the
> > efree(PGG(last_notice)) line].
>
> This isn't our code, so you'd likely have better luck complaining on
> some PHP-related list.  But it looks to me like this code is simply
> trying to free any previous notice message before it stores the new
> one into PGG(last_notice) (whatever the heck that is).  I'm guessing
> that that pointer is uninitialized or has been clobbered somehow.
>
> regards, tom lane
>

Re: PostgreSQL / PHP Overrun Error

From
"Mike Rogers"
Date:
Sorry:
    PHP 4.0.6 (with memory leak patch [download listed right below
php-4.0.6.tar.gz download- It was a problem])
    PostgreSQL 7.1.3
    Apache 1.3.20 (with mod_ssl- but it does the same thing without mod_ssl)
--
Mike

----- Original Message -----
From: "mlw" <markw@mohawksoft.com>
To: "Mike Rogers" <temp6453@hotmail.com>
Cc: "Tom Lane" <tgl@sss.pgh.pa.us>; <pgsql-hackers@postgresql.org>;
<pgsql-php@postgresql.org>; <pgsql-bugs@postgresql.org>
Sent: Wednesday, September 26, 2001 1:55 PM
Subject: Re: [BUGS] PostgreSQL / PHP Overrun Error


> Mike Rogers wrote:
>
> > Well it really isn't your code (true), but the only thing that is
changed is
> > the 7.0-7.1-  Was a data length changed on the return or something that
> > could affect this?
>
> What version of PHP are you using?
>
>
>

Re: [HACKERS] PostgreSQL / PHP Overrun Error

From
"Christopher Kings-Lynne"
Date:
Have you recompiled PHP to link against the new postgres libraries?

Chris

> -----Original Message-----
> From: pgsql-hackers-owner@postgresql.org
> [mailto:pgsql-hackers-owner@postgresql.org]On Behalf Of Mike Rogers
> Sent: Thursday, 27 September 2001 1:07 AM
> To: mlw
> Cc: pgsql-hackers@postgresql.org; pgsql-php@postgresql.org;
> pgsql-bugs@postgresql.org
> Subject: Re: [HACKERS] [BUGS] PostgreSQL / PHP Overrun Error
>
>
> Sorry:
>     PHP 4.0.6 (with memory leak patch [download listed right below
> php-4.0.6.tar.gz download- It was a problem])
>     PostgreSQL 7.1.3
>     Apache 1.3.20 (with mod_ssl- but it does the same thing
> without mod_ssl)
> --
> Mike
>
> ----- Original Message -----
> From: "mlw" <markw@mohawksoft.com>
> To: "Mike Rogers" <temp6453@hotmail.com>
> Cc: "Tom Lane" <tgl@sss.pgh.pa.us>; <pgsql-hackers@postgresql.org>;
> <pgsql-php@postgresql.org>; <pgsql-bugs@postgresql.org>
> Sent: Wednesday, September 26, 2001 1:55 PM
> Subject: Re: [BUGS] PostgreSQL / PHP Overrun Error
>
>
> > Mike Rogers wrote:
> >
> > > Well it really isn't your code (true), but the only thing that is
> changed is
> > > the 7.0-7.1-  Was a data length changed on the return or
> something that
> > > could affect this?
> >
> > What version of PHP are you using?
> >
> >
> >
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>


Re: PostgreSQL / PHP Overrun Error

From
mlw
Date:
Mike Rogers wrote:

> Well it really isn't your code (true), but the only thing that is changed is
> the 7.0-7.1-  Was a data length changed on the return or something that
> could affect this?

What version of PHP are you using?



---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org




Re: PostgreSQL / PHP Overrun Error

From
mlw
Date:
Interesting. I am using that same configuration. We are using the same thing on
our website as well. I have never seen this problem. Weird.

My guess is that you are getting an error. The PHP code is some how mucking
this up. But I would try executing the query in psql and see what comes up.

The PHP code than handles the error may have a fixed langth buffer for speed,
and it is to short for a longer 7.1 error message. Again, I am guessing.

My bet is that the query is failing with an error, so you really have two
problems. A problem in your SQL which is causing you to see a bug in PHP.



Mike Rogers wrote:

> Sorry:
>     PHP 4.0.6 (with memory leak patch [download listed right below
> php-4.0.6.tar.gz download- It was a problem])
>     PostgreSQL 7.1.3
>     Apache 1.3.20 (with mod_ssl- but it does the same thing without mod_ssl)
> --
> Mike
>
> ----- Original Message -----
> From: "mlw" <markw@mohawksoft.com>
> To: "Mike Rogers" <temp6453@hotmail.com>
> Cc: "Tom Lane" <tgl@sss.pgh.pa.us>; <pgsql-hackers@postgresql.org>;
> <pgsql-php@postgresql.org>; <pgsql-bugs@postgresql.org>
> Sent: Wednesday, September 26, 2001 1:55 PM
> Subject: Re: [BUGS] PostgreSQL / PHP Overrun Error
>
> > Mike Rogers wrote:
> >
> > > Well it really isn't your code (true), but the only thing that is
> changed is
> > > the 7.0-7.1-  Was a data length changed on the return or something that
> > > could affect this?
> >
> > What version of PHP are you using?
> >
> >
> >


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)




Re: [PHP] PostgreSQL / PHP Overrun Error

From
Tom Lane
Date:
"Mike Rogers" <temp6453@hotmail.com> writes:
> This problem is of great concern to me and I have been working for days
> trying to debug it myself and find other reports, with little success.  The
> line it claims to be failing on is PHP's ext/pgsql/pgsql.c on line 167 (by
> what this claims) which is the following function [the
> efree(PGG(last_notice)) line].

This isn't our code, so you'd likely have better luck complaining on
some PHP-related list.  But it looks to me like this code is simply
trying to free any previous notice message before it stores the new
one into PGG(last_notice) (whatever the heck that is).  I'm guessing
that that pointer is uninitialized or has been clobbered somehow.

            regards, tom lane

---------------------------(end of broadcast)---------------------------
TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org




Re: [HACKERS] [PHP] PostgreSQL / PHP Overrun Error

From
Tatsuo Ishii
Date:
This is a known problem with PHP 4.0.6. You might want to upgrade to
4.1.0RC2, or try patches made by one of the PHP developers:

ftp://ftp.sra.co.jp/pub/cmd/postgres/php/php-4.0.6-patches.tar.gz

> Mike Rogers wrote:
>
> > Sorry:
> >     PHP 4.0.6 (with memory leak patch [download listed right below
> > php-4.0.6.tar.gz download- It was a problem])
> >     PostgreSQL 7.1.3
> >     Apache 1.3.20 (with mod_ssl- but it does the same thing without mod_ssl)
> > --
> > Mike
> >
> > ----- Original Message -----
> > From: "mlw" <markw@mohawksoft.com>
> > To: "Mike Rogers" <temp6453@hotmail.com>
> > Cc: "Tom Lane" <tgl@sss.pgh.pa.us>; <pgsql-hackers@postgresql.org>;
> > <pgsql-php@postgresql.org>; <pgsql-bugs@postgresql.org>
> > Sent: Wednesday, September 26, 2001 1:55 PM
> > Subject: Re: [BUGS] PostgreSQL / PHP Overrun Error
> >
> > > Mike Rogers wrote:
> > >
> > > > Well it really isn't your code (true), but the only thing that is
> > changed is
> > > > the 7.0-7.1-  Was a data length changed on the return or something that
> > > > could affect this?
> > >
> > > What version of PHP are you using?
> > >
> > >
> > >
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)
>
>
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 5: Have you checked our extensive FAQ?
>
> http://www.postgresql.org/users-lounge/docs/faq.html
>

Re: [PHP] [HACKERS] PostgreSQL / PHP Overrun Error

From
"Christopher Kings-Lynne"
Date:
Have you recompiled PHP to link against the new postgres libraries?

Chris

> -----Original Message-----
> From: pgsql-hackers-owner@postgresql.org
> [mailto:pgsql-hackers-owner@postgresql.org]On Behalf Of Mike Rogers
> Sent: Thursday, 27 September 2001 1:07 AM
> To: mlw
> Cc: pgsql-hackers@postgresql.org; pgsql-php@postgresql.org;
> pgsql-bugs@postgresql.org
> Subject: Re: [HACKERS] [BUGS] PostgreSQL / PHP Overrun Error
>
>
> Sorry:
>     PHP 4.0.6 (with memory leak patch [download listed right below
> php-4.0.6.tar.gz download- It was a problem])
>     PostgreSQL 7.1.3
>     Apache 1.3.20 (with mod_ssl- but it does the same thing
> without mod_ssl)
> --
> Mike
>
> ----- Original Message -----
> From: "mlw" <markw@mohawksoft.com>
> To: "Mike Rogers" <temp6453@hotmail.com>
> Cc: "Tom Lane" <tgl@sss.pgh.pa.us>; <pgsql-hackers@postgresql.org>;
> <pgsql-php@postgresql.org>; <pgsql-bugs@postgresql.org>
> Sent: Wednesday, September 26, 2001 1:55 PM
> Subject: Re: [BUGS] PostgreSQL / PHP Overrun Error
>
>
> > Mike Rogers wrote:
> >
> > > Well it really isn't your code (true), but the only thing that is
> changed is
> > > the 7.0-7.1-  Was a data length changed on the return or
> something that
> > > could affect this?
> >
> > What version of PHP are you using?
> >
> >
> >
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>


Re: [PHP] PostgreSQL / PHP Overrun Error

From
"Mike Rogers"
Date:
Well it really isn't your code (true), but the only thing that is changed is
the 7.0-7.1-  Was a data length changed on the return or something that
could affect this?
--
Mike

----- Original Message -----
From: "Tom Lane" <tgl@sss.pgh.pa.us>
To: "Mike Rogers" <temp6453@hotmail.com>
Cc: <pgsql-hackers@postgresql.org>; <pgsql-php@postgresql.org>;
<pgsql-bugs@postgresql.org>
Sent: Wednesday, September 26, 2001 1:23 PM
Subject: Re: [BUGS] PostgreSQL / PHP Overrun Error


> "Mike Rogers" <temp6453@hotmail.com> writes:
> > This problem is of great concern to me and I have been working for days
> > trying to debug it myself and find other reports, with little success.
The
> > line it claims to be failing on is PHP's ext/pgsql/pgsql.c on line 167
(by
> > what this claims) which is the following function [the
> > efree(PGG(last_notice)) line].
>
> This isn't our code, so you'd likely have better luck complaining on
> some PHP-related list.  But it looks to me like this code is simply
> trying to free any previous notice message before it stores the new
> one into PGG(last_notice) (whatever the heck that is).  I'm guessing
> that that pointer is uninitialized or has been clobbered somehow.
>
> regards, tom lane
>

Re: [PHP] [HACKERS] PostgreSQL / PHP Overrun Error

From
"Mike Rogers"
Date:
There is a problem in PHP-4.0.6.  Please use PHP4.0.7 or 4.0.8 and the
problem will be solved.  This can be obtained from CVS
--
Mike

----- Original Message -----
From: "Christopher Kings-Lynne" <chriskl@familyhealth.com.au>
To: "Mike Rogers" <temp6453@hotmail.com>; "mlw" <markw@mohawksoft.com>
Cc: <pgsql-hackers@postgresql.org>; <pgsql-php@postgresql.org>;
<pgsql-bugs@postgresql.org>
Sent: Wednesday, September 26, 2001 10:31 PM
Subject: RE: [HACKERS] [BUGS] PostgreSQL / PHP Overrun Error


> Have you recompiled PHP to link against the new postgres libraries?
>
> Chris
>
> > -----Original Message-----
> > From: pgsql-hackers-owner@postgresql.org
> > [mailto:pgsql-hackers-owner@postgresql.org]On Behalf Of Mike Rogers
> > Sent: Thursday, 27 September 2001 1:07 AM
> > To: mlw
> > Cc: pgsql-hackers@postgresql.org; pgsql-php@postgresql.org;
> > pgsql-bugs@postgresql.org
> > Subject: Re: [HACKERS] [BUGS] PostgreSQL / PHP Overrun Error
> >
> >
> > Sorry:
> >     PHP 4.0.6 (with memory leak patch [download listed right below
> > php-4.0.6.tar.gz download- It was a problem])
> >     PostgreSQL 7.1.3
> >     Apache 1.3.20 (with mod_ssl- but it does the same thing
> > without mod_ssl)
> > --
> > Mike
> >
> > ----- Original Message -----
> > From: "mlw" <markw@mohawksoft.com>
> > To: "Mike Rogers" <temp6453@hotmail.com>
> > Cc: "Tom Lane" <tgl@sss.pgh.pa.us>; <pgsql-hackers@postgresql.org>;
> > <pgsql-php@postgresql.org>; <pgsql-bugs@postgresql.org>
> > Sent: Wednesday, September 26, 2001 1:55 PM
> > Subject: Re: [BUGS] PostgreSQL / PHP Overrun Error
> >
> >
> > > Mike Rogers wrote:
> > >
> > > > Well it really isn't your code (true), but the only thing that is
> > changed is
> > > > the 7.0-7.1-  Was a data length changed on the return or
> > something that
> > > > could affect this?
> > >
> > > What version of PHP are you using?
> > >
> > >
> > >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 4: Don't 'kill -9' the postmaster
> >
>
>

Re: [PHP] PostgreSQL / PHP Overrun Error

From
"Mike Rogers"
Date:
Sorry:
    PHP 4.0.6 (with memory leak patch [download listed right below
php-4.0.6.tar.gz download- It was a problem])
    PostgreSQL 7.1.3
    Apache 1.3.20 (with mod_ssl- but it does the same thing without mod_ssl)
--
Mike

----- Original Message -----
From: "mlw" <markw@mohawksoft.com>
To: "Mike Rogers" <temp6453@hotmail.com>
Cc: "Tom Lane" <tgl@sss.pgh.pa.us>; <pgsql-hackers@postgresql.org>;
<pgsql-php@postgresql.org>; <pgsql-bugs@postgresql.org>
Sent: Wednesday, September 26, 2001 1:55 PM
Subject: Re: [BUGS] PostgreSQL / PHP Overrun Error


> Mike Rogers wrote:
>
> > Well it really isn't your code (true), but the only thing that is
changed is
> > the 7.0-7.1-  Was a data length changed on the return or something that
> > could affect this?
>
> What version of PHP are you using?
>
>
>

Re: [PHP] PostgreSQL / PHP Overrun Error

From
mlw
Date:
Mike Rogers wrote:

> Well it really isn't your code (true), but the only thing that is changed is
> the 7.0-7.1-  Was a data length changed on the return or something that
> could affect this?

What version of PHP are you using?



---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org




Re: [PHP] PostgreSQL / PHP Overrun Error

From
mlw
Date:
Interesting. I am using that same configuration. We are using the same thing on
our website as well. I have never seen this problem. Weird.

My guess is that you are getting an error. The PHP code is some how mucking
this up. But I would try executing the query in psql and see what comes up.

The PHP code than handles the error may have a fixed langth buffer for speed,
and it is to short for a longer 7.1 error message. Again, I am guessing.

My bet is that the query is failing with an error, so you really have two
problems. A problem in your SQL which is causing you to see a bug in PHP.



Mike Rogers wrote:

> Sorry:
>     PHP 4.0.6 (with memory leak patch [download listed right below
> php-4.0.6.tar.gz download- It was a problem])
>     PostgreSQL 7.1.3
>     Apache 1.3.20 (with mod_ssl- but it does the same thing without mod_ssl)
> --
> Mike
>
> ----- Original Message -----
> From: "mlw" <markw@mohawksoft.com>
> To: "Mike Rogers" <temp6453@hotmail.com>
> Cc: "Tom Lane" <tgl@sss.pgh.pa.us>; <pgsql-hackers@postgresql.org>;
> <pgsql-php@postgresql.org>; <pgsql-bugs@postgresql.org>
> Sent: Wednesday, September 26, 2001 1:55 PM
> Subject: Re: [BUGS] PostgreSQL / PHP Overrun Error
>
> > Mike Rogers wrote:
> >
> > > Well it really isn't your code (true), but the only thing that is
> changed is
> > > the 7.0-7.1-  Was a data length changed on the return or something that
> > > could affect this?
> >
> > What version of PHP are you using?
> >
> >
> >


---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
    (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)




[PG MAIL LISTS] SEND OUT ALL????

From
"Mike Rogers"
Date:
Why did it just send out tons of mail since September of this year- every
message?
--
Mike


Re: [HACKERS] [PG MAIL LISTS] SEND OUT ALL????

From
"Marc G. Fournier"
Date:
someone, either intentially or accidentally, sent out a load to the lists
...


On Fri, 16 Nov 2001, Mike Rogers wrote:

> Why did it just send out tons of mail since September of this year- every
> message?
> --
> Mike
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>


Re: [HACKERS] [PG MAIL LISTS] SEND OUT ALL????

From
"Mike Rogers"
Date:
if you look at the originating time for all of the messages that got sent
out of when it was sent from the host machine (with HELO host).  Clearly it
was done on an admin side.
--
Mike

----- Original Message -----
From: "Marc G. Fournier" <scrappy@hub.org>
To: "Mike Rogers" <temp6453@hotmail.com>
Cc: <pgsql-hackers@postgresql.org>; <pgsql-php@postgresql.org>;
<pgsql-bugs@postgresql.org>
Sent: Friday, November 16, 2001 3:26 PM
Subject: Re: [BUGS] [HACKERS] [PG MAIL LISTS] SEND OUT ALL????


>
> someone, either intentially or accidentally, sent out a load to the lists
> ...
>
>
> On Fri, 16 Nov 2001, Mike Rogers wrote:
>
> > Why did it just send out tons of mail since September of this year-
every
> > message?
> > --
> > Mike
> >
> >
> > ---------------------------(end of broadcast)---------------------------
> > TIP 4: Don't 'kill -9' the postmaster
> >
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org
>