pg.ddx.io pgsql-odbc@postgresql.org mailing list archive
help / color / mirror / Atom feedStatic analysis run
3+ messages / 2 participants
[nested] [flat]
* Static analysis run
@ 2005-07-22 15:18 Tomas Skäre <tomas@nocrew.org>
0 siblings, 0 replies; 3+ messages in thread
From: tomas@nocrew.org @ 2005-07-22 15:18 UTC (permalink / raw)
To: pgsql-odbc
We use psqlodbc in one of our projects at my company and we recently
bought a static source code analysis program (Klocwork) to run on our
own software. Since we use psqlodbc, I also ran it on that and it
found a few things. This was run on the CVS head branch from this
today (fri 22 july).
Attached is a diff with some fixes that I managed myself. Then I also
have some places that were not as easy for me to fix, but maybe some
of you that know the code better can do it. Here is a list with
things, some might not be correct, since this tool sometimes thinks
there's an error where there aren't. Row numbers might not be exact
because of some local changes, but they should be almost right.
convert.c in ResolveOneParam:2651 allocbuf is allocated, further down
(2785), CVT_APPEND_CHAR and CVT_APPEND_STR are used a lot, and these
macros may return from the function, giving a memory leak for
allocbuf.
environ.c in PGAPI_FreeEnv:89 env is freed even if EN_Destructor
returns false above, which means it's accessing freed memory.
info.c in PGAPI_Statistics:2623 If SC_MALLOC_return_with_error
returns, column_names allocated above is lost.
odbcapi30w.c in SQLGetDescFieldW:128 blen is not initialised before
sent to utf8_to_ucs2(). The same thing exists in SQLColAttributeW:287
and SQLGetDiagFieldW:345.
results.c in SC_pos_reload_needed:2189 rows_per_fetch is
uninitialised, if create_from_scratch is false.
These are the things that I saw just looking through the report pretty
quickly. There are a lot of reports about dereferenced NULL pointers,
but I haven't looked more closely at any of those. Most of them comes
from not checking what malloc and family returns. It also complains a
lot about strcpy and sprintf not checking boundaries. Those might not
at all be errors, but then again they could cause buffer overflows.
If you are interested, I can send the full report (200KB html, 295
entries including the ones in the patch and the above things), and if
someone has time, that person can go through the list.
Greetings,
Tomas
Attachments:
kw.diff (text/plain, 2.7K) download
Index: connection.c
===================================================================
RCS file: /usr/local/cvsroot/psqlodbc/psqlodbc/connection.c,v
retrieving revision 1.97
diff -u -r1.97 connection.c
--- connection.c 20 Jul 2005 14:50:21 -0000 1.97
+++ connection.c 22 Jul 2005 14:46:32 -0000
@@ -2360,13 +2360,20 @@
CC_conninfo_init(&(rv->connInfo));
rv->stmts = (StatementClass **) malloc(sizeof(StatementClass *) * STMT_INCREMENT);
if (!rv->stmts)
+ {
+ free(rv);
return NULL;
+ }
memset(rv->stmts, 0, sizeof(StatementClass *) * STMT_INCREMENT);
rv->num_stmts = STMT_INCREMENT;
rv->descs = (DescriptorClass **) malloc(sizeof(DescriptorClass *) * STMT_INCREMENT);
if (!rv->descs)
+ {
+ free(rv->stmts);
+ free(rv);
return NULL;
+ }
memset(rv->descs, 0, sizeof(DescriptorClass *) * STMT_INCREMENT);
rv->num_descs = STMT_INCREMENT;
@@ -2857,6 +2864,7 @@
if((!res) || (res->status == PGRES_EMPTY_QUERY) )
{
QR_Destructor(res);
+ res = NULL;
goto cleanup;
}
else
@@ -3141,6 +3149,7 @@
{
CC_set_error(self, CONNECTION_COULD_NOT_RECEIVE, "Could not allocate memory for result set");
QR_Destructor(qres);
+ return NULL;
}
qres->status = PQresultStatus(pgres);
if( (PQresultStatus(pgres) == PGRES_COMMAND_OK) )
Index: convert.c
===================================================================
RCS file: /usr/local/cvsroot/psqlodbc/psqlodbc/convert.c,v
retrieving revision 1.126
diff -u -r1.126 convert.c
--- convert.c 15 Jul 2005 09:08:50 -0000 1.126
+++ convert.c 22 Jul 2005 14:46:33 -0000
@@ -1578,7 +1578,7 @@
while (qp->statement[qp->opos] != '\0' && qp->statement[qp->opos] != ch) \
{ \
buf[c++] = qp->statement[qp->opos++]; \
- if (c >= maxsize) \
+ if (c >= maxsize - 1) \
break; \
} \
if (qp->statement[qp->opos] == '\0') \
Index: info.c
===================================================================
RCS file: /usr/local/cvsroot/psqlodbc/psqlodbc/info.c,v
retrieving revision 1.121
diff -u -r1.121 info.c
--- info.c 13 Jul 2005 14:23:35 -0000 1.121
+++ info.c 22 Jul 2005 14:46:33 -0000
@@ -1304,7 +1304,7 @@
#else
prefix[i] = strtok(prefixes, ";");
#endif /* HAVE_STRTOK_R */
- while (prefix[i] && i < sizeof(prefix))
+ while (i < 31 && prefix[i])
#ifdef HAVE_STRTOK_R
prefix[++i] = strtok_r(NULL, ";", &last);
#else
@@ -1328,7 +1328,7 @@
#else
table_type[i] = strtok(table_types, ",");
#endif /* HAVE_STRTOK_R */
- while (table_type[i] && i < 32)
+ while (i < 31 && table_type[i])
#ifdef HAVE_STRTOK_R
table_type[++i] = strtok_r(NULL, ",", &last);
#else
@@ -3815,6 +3815,7 @@
}
if (pkey_alloced)
free(pkey_text);
+ pkey_alloced = FALSE;
/* Get to next primary key */
for (k = 0; k < 2; k++)
pkey_ptr += strlen(pkey_ptr) + 1;
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Static analysis run
@ 2005-07-22 15:42 Dave Page <dpage@vale-housing.co.uk>
0 siblings, 0 replies; 3+ messages in thread
From: Dave Page @ 2005-07-22 15:42 UTC (permalink / raw)
To: Tomas Skäre <tomas@nocrew.org>; pgsql-odbc
Thanks Tomas,
I'll review the patch and apply it as soon as I get some time. I would be interested in a copy of the full report if you don't mind.
Thanks, Dave.
> -----Original Message-----
> From: pgsql-odbc-owner@postgresql.org
> [mailto:pgsql-odbc-owner@postgresql.org] On Behalf Of Tomas Skäre
> Sent: 22 July 2005 16:19
> To: pgsql-odbc@postgresql.org
> Subject: [ODBC] Static analysis run
>
> Hi,
>
> We use psqlodbc in one of our projects at my company and we recently
> bought a static source code analysis program (Klocwork) to run on our
> own software. Since we use psqlodbc, I also ran it on that and it
> found a few things. This was run on the CVS head branch from this
> today (fri 22 july).
>
> Attached is a diff with some fixes that I managed myself. Then I also
> have some places that were not as easy for me to fix, but maybe some
> of you that know the code better can do it. Here is a list with
> things, some might not be correct, since this tool sometimes thinks
> there's an error where there aren't. Row numbers might not be exact
> because of some local changes, but they should be almost right.
>
>
> convert.c in ResolveOneParam:2651 allocbuf is allocated, further down
> (2785), CVT_APPEND_CHAR and CVT_APPEND_STR are used a lot, and these
> macros may return from the function, giving a memory leak for
> allocbuf.
>
> environ.c in PGAPI_FreeEnv:89 env is freed even if EN_Destructor
> returns false above, which means it's accessing freed memory.
>
> info.c in PGAPI_Statistics:2623 If SC_MALLOC_return_with_error
> returns, column_names allocated above is lost.
>
> odbcapi30w.c in SQLGetDescFieldW:128 blen is not initialised before
> sent to utf8_to_ucs2(). The same thing exists in SQLColAttributeW:287
> and SQLGetDiagFieldW:345.
>
> results.c in SC_pos_reload_needed:2189 rows_per_fetch is
> uninitialised, if create_from_scratch is false.
>
>
> These are the things that I saw just looking through the report pretty
> quickly. There are a lot of reports about dereferenced NULL pointers,
> but I haven't looked more closely at any of those. Most of them comes
> from not checking what malloc and family returns. It also complains a
> lot about strcpy and sprintf not checking boundaries. Those might not
> at all be errors, but then again they could cause buffer overflows.
>
> If you are interested, I can send the full report (200KB html, 295
> entries including the ones in the patch and the above things), and if
> someone has time, that person can go through the list.
>
>
> Greetings,
>
> Tomas
>
>
>
^ permalink raw reply [nested|flat] 3+ messages in thread
* Re: Static analysis run
@ 2005-07-22 21:53 Dave Page <dpage@vale-housing.co.uk>
0 siblings, 0 replies; 3+ messages in thread
From: Dave Page @ 2005-07-22 21:53 UTC (permalink / raw)
To: Tomas Skäre <tomas@nocrew.org>; pgsql-odbc
> -----Original Message-----
> From: pgsql-odbc-owner@postgresql.org
> [mailto:pgsql-odbc-owner@postgresql.org] On Behalf Of Tomas Skäre
> Sent: 22 July 2005 16:19
> To: pgsql-odbc@postgresql.org
> Subject: [ODBC] Static analysis run
>
> Hi,
>
> We use psqlodbc in one of our projects at my company and we recently
> bought a static source code analysis program (Klocwork) to run on our
> own software. Since we use psqlodbc, I also ran it on that and it
> found a few things. This was run on the CVS head branch from this
> today (fri 22 july).
>
> Attached is a diff with some fixes that I managed myself.
Thanks, patch applied.
Regards, Dave.
^ permalink raw reply [nested|flat] 3+ messages in thread
end of thread, other threads:[~2005-07-22 21:53 UTC | newest]
Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2005-07-22 15:18 Static analysis run Tomas Skäre <tomas@nocrew.org>
2005-07-22 15:42 Re: Static analysis run Dave Page <dpage@vale-housing.co.uk>
2005-07-22 21:53 Re: Static analysis run Dave Page <dpage@vale-housing.co.uk>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox