Обсуждение: to_char() dumps core

Поиск
Список
Период
Сортировка

to_char() dumps core

От
Tatsuo Ishii
Дата:
In 7.0.2 
  select to_char(sum(n),'999') from t1;

causes backend dump a core if n is a float/numeric ...data type AND if
sum(n) returns NULL. This seems due to a bad null pointer handling for
aruguments of pass-by-reference data types.  I think just a simple
null pointer checking at very top of each function (for example
float4_to_char()) would solve the problem.  Comments?

test=# create table t1(f float);
CREATE
test=# select to_char(sum(f),'999') from t1;
pqReadData() -- backend closed the channel unexpectedly.This probably means the backend terminated abnormallybefore or
whileprocessing the request.
 
The connection to the server was lost. Attempting reset: Failed.


Re: to_char() dumps core

От
Karel Zak
Дата:
On Fri, 20 Oct 2000, Tatsuo Ishii wrote:

> In 7.0.2 
> 
>    select to_char(sum(n),'999') from t1;
> 
> causes backend dump a core if n is a float/numeric ...data type AND if
> sum(n) returns NULL. This seems due to a bad null pointer handling for
> aruguments of pass-by-reference data types.  I think just a simple
> null pointer checking at very top of each function (for example
> float4_to_char()) would solve the problem.  Comments?
In the 7.1devel it's correct, but here it's bug, IMHO it bear on changes
in the 7.1's fmgr, because code is same in both versions for this. On Monday, 
I try fix it for 7.0.3 
                    Karel
> test=# create table t1(f float);
> CREATE
> test=# select to_char(sum(f),'999') from t1;
> pqReadData() -- backend closed the channel unexpectedly.
>     This probably means the backend terminated abnormally
>     before or while processing the request.
> The connection to the server was lost. Attempting reset: Failed.
> 



Re: to_char() dumps core

От
Tom Lane
Дата:
Tatsuo Ishii <t-ishii@sra.co.jp> writes:
> In 7.0.2 
>    select to_char(sum(n),'999') from t1;

> causes backend dump a core if n is a float/numeric ...data type AND if
> sum(n) returns NULL. This seems due to a bad null pointer handling for
> aruguments of pass-by-reference data types.  I think just a simple
> null pointer checking at very top of each function (for example
> float4_to_char()) would solve the problem.  Comments?

Just a note to remind everyone, since I haven't yet updated the
documentation for the new-fmgr changes: under the 7.1 fmgr it is *no
longer necessary* to check for NULL pointer in function execution
routines, assuming that your function is marked "strict" in pg_proc
(as nearly all built-in functions are).  The fmgr will not call such
a function in the first place, if any of its inputs are NULLs.

So, while adding the NULL-pointer checks is an OK patch for 7.0.*,
don't stick such checks into current sources.

(Also, if you do want to check for a NULL input in current sources,
looking for a NULL pointer is the wrong way to code it anyway;
PG_ARGISNULL(n) is the right way.)
        regards, tom lane