Re: Lack of Sanity Checking in file 'misc.c' for PostgreSQL 9.4.x

From: Michael Paquier <michael(dot)paquier(at)gmail(dot)com>
To: Bill Parker <wp02855(at)gmail(dot)com>
Cc: PostgreSQL mailing lists <pgsql-bugs(at)postgresql(dot)org>, Michael Meskes <meskes(at)postgresql(dot)org>
Subject: Re: Lack of Sanity Checking in file 'misc.c' for PostgreSQL 9.4.x
Date: 2015-06-12 06:53:43
Message-ID: CAB7nPqRdAjUB9pTL3LRSQ33dr4qv-rvHduj2DJxibSVA0owTTA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

(Adding Michael Meskes in CC:)

On Fri, Jun 12, 2015 at 4:11 AM, Bill Parker <wp02855(at)gmail(dot)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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Michael Paquier 2015-06-12 07:05:44 Re: Lack of Sanity Checking in file 'pctcl.c' for PostgreSQL 9.4.x
Previous Message Fujii Masao 2015-06-12 05:43:41 Re: BUG #13368: standby cluster immediately promotes after pg_basebackup from previously promoted master