Thread: Please, fix!!! The backend can crash on your system!

Please, fix!!! The backend can crash on your system!

From
Alexis Wilke
Date:
If PostgreSQL failed to compile on your computer or you found a bug that
is likely to be specific to one platform then please fill out this form
and e-mail it to pgsql-ports@postgresql.org.

To report any other bug, fill out the form below and e-mail it to
pgsql-bugs@postgresql.org.

If you not only found the problem but solved it and generated a patch
then e-mail it to pgsql-patches@postgresql.org instead.  Please use the
command "diff -c" to generate the patch.

You may also enter a bug report at http://www.postgresql.org/ instead of
e-mail-ing this form.

============================================================================
                        POSTGRESQL BUG REPORT TEMPLATE
============================================================================


Your name        :    Alexis Wilke
Your email address    :    alexis@m2osw.com


System Configuration
---------------------
  Architecture (example: Intel Pentium)      : trust me, doesn't matter

  Operating System (example: Linux 2.0.26 ELF)     : trust me, doesn't matter

  PostgreSQL version (example: PostgreSQL-7.0):   since PostgreSQL-6.5.x
                                                  and still in the code

  Compiler used (example:  gcc 2.8.0)        : trust me, doesn't matter


Please enter a FULL description of your problem:
------------------------------------------------

It crashes when pg_database is too large. This is because
the index is compare to max with <= instead of <. I already
fixed the bug on my system. That's at line



Please describe a way to repeat the problem.   Please try to provide a
concise reproducible example, if at all possible:
----------------------------------------------------------------------

Create many database (or create/destroy the same many times).

Once the pg_database is more than one page (is 16Kb or more) then it
starts
crashing. (may not crash on all systems, but trust me, my fix
will work GREAT).



If you know how this problem might be fixed, list the solution below:
---------------------------------------------------------------------

Okay, so go in the following file:

./src/backend/utils/misc/database.c

and move to the line #183 (V7.0.1)

There, fix the for() as is:

    for(i = 0; i < max; i++)

Why? Well, because 'i' starts at 0, therefore, you
can't access the tuple number 'max'. If you look in
other source files, you will quickly see that all
these for() loops are starting with an index of
1 and use some special functions/macros to access
the tuple data.





__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/?.refer=text

Re: Please, fix!!! The backend can crash on your system!

From
Bruce Momjian
Date:
In the current sources, I see:

        for (lineoff = FirstOffsetNumber; lineoff <= max; lineoff++)

so it looks like we have this fixed.  You can check the 7.1RC1.


>
> If PostgreSQL failed to compile on your computer or you found a bug that
> is likely to be specific to one platform then please fill out this form
> and e-mail it to pgsql-ports@postgresql.org.
>
> To report any other bug, fill out the form below and e-mail it to
> pgsql-bugs@postgresql.org.
>
> If you not only found the problem but solved it and generated a patch
> then e-mail it to pgsql-patches@postgresql.org instead.  Please use the
> command "diff -c" to generate the patch.
>
> You may also enter a bug report at http://www.postgresql.org/ instead of
> e-mail-ing this form.
>
> ============================================================================
>                         POSTGRESQL BUG REPORT TEMPLATE
> ============================================================================
>
>
> Your name        :    Alexis Wilke
> Your email address    :    alexis@m2osw.com
>
>
> System Configuration
> ---------------------
>   Architecture (example: Intel Pentium)      : trust me, doesn't matter
>
>   Operating System (example: Linux 2.0.26 ELF)     : trust me, doesn't matter
>
>   PostgreSQL version (example: PostgreSQL-7.0):   since PostgreSQL-6.5.x
>                                                   and still in the code
>
>   Compiler used (example:  gcc 2.8.0)        : trust me, doesn't matter
>
>
> Please enter a FULL description of your problem:
> ------------------------------------------------
>
> It crashes when pg_database is too large. This is because
> the index is compare to max with <= instead of <. I already
> fixed the bug on my system. That's at line
>
>
>
> Please describe a way to repeat the problem.   Please try to provide a
> concise reproducible example, if at all possible:
> ----------------------------------------------------------------------
>
> Create many database (or create/destroy the same many times).
>
> Once the pg_database is more than one page (is 16Kb or more) then it
> starts
> crashing. (may not crash on all systems, but trust me, my fix
> will work GREAT).
>
>
>
> If you know how this problem might be fixed, list the solution below:
> ---------------------------------------------------------------------
>
> Okay, so go in the following file:
>
> ./src/backend/utils/misc/database.c
>
> and move to the line #183 (V7.0.1)
>
> There, fix the for() as is:
>
>     for(i = 0; i < max; i++)
>
> Why? Well, because 'i' starts at 0, therefore, you
> can't access the tuple number 'max'. If you look in
> other source files, you will quickly see that all
> these for() loops are starting with an index of
> 1 and use some special functions/macros to access
> the tuple data.
>
>
>
>
>
> __________________________________________________
> Do You Yahoo!?
> Get email at your own domain with Yahoo! Mail.
> http://personal.mail.yahoo.com/?.refer=text
>
> ---------------------------(end of broadcast)---------------------------
> TIP 4: Don't 'kill -9' the postmaster
>


--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026