Re: Server crash while trying to read expression using pg_get_expr() - Mailing list pgsql-bugs

From Heikki Linnakangas
Subject Re: Server crash while trying to read expression using pg_get_expr()
Date
Msg-id 4C075BA6.8080207@enterprisedb.com
Whole thread Raw
In response to Server crash while trying to read expression using pg_get_expr()  (Rushabh Lathia <rushabh.lathia@gmail.com>)
List pgsql-bugs
On 03/06/10 10:21, Rushabh Lathia wrote:
> Server crash while trying to read expression(wrong) using pg_get_expr().
>
> postgres=# SELECT pg_get_expr('{FUNCEXPR', 1255);
> server closed the connection unexpectedly
> This probably means the server terminated abnormally
> before or while processing the request.
> The connection to the server was lost. Attempting reset: Failed.

In readfuncs.c, we don't check the return value of pg_strtok, and pass a
NULL to atoi(). The fix is pretty straightforward, we just have to be
more careful with validating the input, see attached patch.

However, I'm afraid we're lacking in input validation of read-funcs in
general. After some random hacking, I found this:

postgres=# SELECT pg_get_expr('{FUNCEXPR 1 2 3 4 4 5 6  7 8 9 9 } }', 1255);
server closed the connection unexpectedly
    This probably means the server terminated abnormally
    before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.

Which still crashes despite the patch. Does anyone have an idea on how
to validate the input in a more wholesale fashion, so that we don't need
to plug these holes one by one?

--
   Heikki Linnakangas
   EnterpriseDB   http://www.enterprisedb.com

Attachment

pgsql-bugs by date:

Previous
From: Rushabh Lathia
Date:
Subject: Server crash while trying to read expression using pg_get_expr()
Next
From: "Hartmut Goebel"
Date:
Subject: BUG #5488: pg_dump does not quote column names -> pg_restore may fail when upgrading