Re: Lack of Sanity Checking in file 'misc.c' for PostgreSQL 9.4.x - Mailing list pgsql-bugs

From Michael Paquier
Subject Re: Lack of Sanity Checking in file 'misc.c' for PostgreSQL 9.4.x
Date
Msg-id CAB7nPqRdAjUB9pTL3LRSQ33dr4qv-rvHduj2DJxibSVA0owTTA@mail.gmail.com
Whole thread Raw
In response to Lack of Sanity Checking in file 'misc.c' for PostgreSQL 9.4.x  (Bill Parker <wp02855@gmail.com>)
Responses Re: Lack of Sanity Checking in file 'misc.c' for PostgreSQL 9.4.x
List pgsql-bugs
(Adding Michael Meskes in CC:)

On Fri, Jun 12, 2015 at 4:11 AM, Bill Parker <wp02855@gmail.com> wrote:
> --- misc.c.orig 2015-06-11 09:23:13.807020490 -0700
> +++ misc.c      2015-06-11 09:32:10.077177669 -0700
> @@ -143,6 +143,9 @@
>         if (sqlca == NULL)
>         {
>                 sqlca = malloc(sizeof(struct sqlca_t));
> +               if (sqlca == NULL) {    /*  malloc() failed, now what should
> we do? */
> +                   ecpg_log("Unable to allocate memory in
> ECPGget_sqlca()\n");
> +               }
>                 ecpg_init_sqlca(sqlca);
>                 pthread_setspecific(sqlca_key, sqlca);
>         }
>
> Please feel free to review and comment on the above patch file...
>
> I am attaching the patch file to this bug report
>
> Bill Parker (wp02855 at gmail dot com)

Nice catch. Regarding your patch, it seems to me that this is not
enough. I think that we should return NULL with ECPGget_sqlca in case
of an OOM instead of logging a message with ecpg_log and let each code
path decide what to do when sqlca is NULL. Some code paths can
directly use ecpg_raise with ECPG_OUT_OF_MEMORY. Other code paths,
like the ones in error.c will need to show up with appropriate error
messages.
--
Michael

pgsql-bugs by date:

Previous
From: Fujii Masao
Date:
Subject: Re: BUG #13368: standby cluster immediately promotes after pg_basebackup from previously promoted master
Next
From: Michael Paquier
Date:
Subject: Re: Lack of Sanity Checking in file 'pctcl.c' for PostgreSQL 9.4.x