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

From: Bill Parker <wp02855(at)gmail(dot)com>
To: pgsql-bugs(at)postgresql(dot)org
Subject: Lack of Sanity Checking in file 'misc.c' for PostgreSQL 9.4.x
Date: 2015-06-11 19:11:37
Message-ID: CAFrbyQy2U+OrNpqxdnLfXxEiO5M3RVr4SoS7Hrg3srBO8KS9dw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

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

Your name : Bill Parker
Your email address : wp02855 at gmail dot com

System Configuration:
---------------------
Architecture (example: Intel Pentium) : x86/x86-64/AMD

Operating System (example: Linux 2.4.18) : Linux 3.11.6-4

PostgreSQL version (example: PostgreSQL 9.4.3): PostgreSQL 9.4.x

Compiler used (example: gcc 3.3.5) : gcc version 4.8.1

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

Hello All,

In reviewing some code, in directory
'postgresql-9.4.3/src/interfaces/ecpg/ecpglib',
file 'misc.c', there are several instances where a call to malloc()
is made, but no check for a return value of NULL is made, which
would indicate failure. Additionally, if sqlca = malloc() fails,
ecpg_init_sqlca would be called with variable 'sqlca' equal to NULL?

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

The patch file below addresses these issues:

--- 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)

Attachment Content-Type Size
misc.c.patch application/octet-stream 403 bytes

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Bill Parker 2015-06-11 19:22:41 Lack of Sanity Checking in file 'pctcl.c' for PostgreSQL 9.4.x
Previous Message pradit.mix-it 2015-06-11 05:53:57 BUG #13431: install readline not complete