pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Static analysis fix request
4+ messages / 2 participants
[nested] [flat]

* Static analysis fix request
@ 2014-01-06 09:00 Pavel Raiskup <praiskup@redhat.com>
  2014-01-06 10:14 ` Re: Static analysis fix request Heikki Linnakangas <hlinnakangas@vmware.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Pavel Raiskup @ 2014-01-06 09:00 UTC (permalink / raw)
  To: pgsql-odbc

* Attached fix for overrun.  This is imo worth fixing.

* Attached added gcc & Coverity warnings (added between 9.2.1 and 9.3.1)

Pavel

-- 
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc

Attachments:

0001-Fix-off-by-one-overrun.patch (text/x-patch, 1.4K) download From f891d6a35c28fc25bae39ac466b9ae203f219eb5 Mon Sep 17 00:00:00 2001 From: Pavel Raiskup <praiskup@redhat.com> Date: Mon, 6 Jan 2014 09:26:43 +0100 Subject: [PATCH] Fix off-by-one overrun Detected by Coverity --- info.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/info.c b/info.c index 9fd034f..14e3876 100644 --- a/info.c +++ b/info.c @@ -1686,11 +1686,11 @@ retry_public_schema: #else prefix[i] = strtok(prefixes, ";"); #endif /* HAVE_STRTOK_R */ - while (i < sizeof(prefix) / sizeof(char *) && prefix[i]) + for (i++; i < sizeof(prefix) / sizeof(char *) && prefix[i]; i++) #ifdef HAVE_STRTOK_R - prefix[++i] = strtok_r(NULL, ";", &last); + prefix[i] = strtok_r(NULL, ";", &last); #else - prefix[++i] = strtok(NULL, ";"); + prefix[i] = strtok(NULL, ";"); #endif /* HAVE_STRTOK_R */ /* Parse the desired table types to return */ @@ -1720,11 +1720,11 @@ retry_public_schema: #else table_type[i] = strtok(table_types, ","); #endif /* HAVE_STRTOK_R */ - while (i < sizeof(table_type) / sizeof(char *) && table_type[i]) + for (i++; i < sizeof(table_type) / sizeof(char *) && table_type[i]; i++) #ifdef HAVE_STRTOK_R - table_type[++i] = strtok_r(NULL, ",", &last); + table_type[i] = strtok_r(NULL, ",", &last); #else - table_type[++i] = strtok(NULL, ","); + table_type[i] = strtok(NULL, ","); #endif /* HAVE_STRTOK_R */ /* Check for desired table types to return */ -- 1.8.4.2
coverity_and_gcc.err.zip (application/zip, 16.3K) download ^ permalink raw reply [nested|flat] 4+ messages in thread

* Re: Static analysis fix request
  2014-01-06 09:00 Static analysis fix request Pavel Raiskup <praiskup@redhat.com>
@ 2014-01-06 10:14 ` Heikki Linnakangas <hlinnakangas@vmware.com>
  2014-01-06 14:48   ` Re: Static analysis fix request Pavel Raiskup <praiskup@redhat.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Heikki Linnakangas @ 2014-01-06 10:14 UTC (permalink / raw)
  To: Pavel Raiskup <praiskup@redhat.com>; +Cc: pgsql-odbc

On 01/06/2014 11:00 AM, Pavel Raiskup wrote:
> * Attached fix for overrun.  This is imo worth fixing.
>
> * Attached added gcc & Coverity warnings (added between 9.2.1 and 9.3.1)

Ironically, I changed the code the way it is now, per previous static 
analyzer report. It was off by even more before.

And I think it's still wrong :-). The code that follows expects the 
prefix[] array to be terminated by a NULL entry.

That code is really difficult to read, and hence difficult to get 
correct. Since we've already been burned twice by it, let's make it less 
error-prone. How about the attached? Does that look correct to you?

(Perhaps we should just rip out the prefix stuff, though. It's only 
there to support pre-7.3 servers)

- Heikki

-- 
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc

Attachments:

fix-prefixes-and-table_types-loops-2.patch (text/x-diff, 4.8K) download *** a/info.c --- b/info.c *************** *** 1544,1553 **** PGAPI_Tables( ConnectionClass *conn; ConnInfo *ci; char *escCatName = NULL, *escSchemaName = NULL, *escTableName = NULL; ! char *prefix[32], prefixes[MEDIUM_REGISTRY_LEN]; ! char *table_type[32], ! table_types[MAX_INFO_STRING]; char show_system_tables, show_regular_tables, show_views; --- 1544,1554 ---- ConnectionClass *conn; ConnInfo *ci; char *escCatName = NULL, *escSchemaName = NULL, *escTableName = NULL; ! /* Support up to 32 system table prefixes. Should be more than enough. */ ! #define MAX_PREFIXES 32 ! char *prefix[MAX_PREFIXES], prefixes[MEDIUM_REGISTRY_LEN]; ! int nprefixes; char show_system_tables, show_regular_tables, show_views; *************** *** 1678,1698 **** retry_public_schema: " and relname %s'%s'", op_string, escTableName); } ! /* Parse the extra systable prefix */ strcpy(prefixes, ci->drivers.extra_systable_prefixes); ! i = 0; ! #ifdef HAVE_STRTOK_R ! prefix[i] = strtok_r(prefixes, ";", &last); ! #else ! prefix[i] = strtok(prefixes, ";"); ! #endif /* HAVE_STRTOK_R */ ! while (i < sizeof(prefix) / sizeof(char *) && prefix[i]) #ifdef HAVE_STRTOK_R ! prefix[++i] = strtok_r(NULL, ";", &last); #else ! prefix[++i] = strtok(NULL, ";"); #endif /* HAVE_STRTOK_R */ /* Parse the desired table types to return */ show_system_tables = FALSE; show_regular_tables = FALSE; --- 1679,1704 ---- " and relname %s'%s'", op_string, escTableName); } ! /* ! * Parse the extra systable prefix configuration variable into an array ! * of prefixes. ! */ strcpy(prefixes, ci->drivers.extra_systable_prefixes); ! for (i = 0; i < MAX_PREFIXES; i++) ! { ! char *str = (i == 0) ? prefixes : NULL; ! #ifdef HAVE_STRTOK_R ! prefix[i] = strtok_r(str, ";", &last); #else ! prefix[i] = strtok(str, ";"); #endif /* HAVE_STRTOK_R */ + if (prefix[i] == NULL) + break; + } + nprefixes = i; + /* Parse the desired table types to return */ show_system_tables = FALSE; show_regular_tables = FALSE; *************** *** 1713,1739 **** retry_public_schema: #endif /* ODBCVER */ else { ! strcpy(table_types, tableType); ! i = 0; ! #ifdef HAVE_STRTOK_R ! table_type[i] = strtok_r(table_types, ",", &last); ! #else ! table_type[i] = strtok(table_types, ","); ! #endif /* HAVE_STRTOK_R */ ! while (i < sizeof(table_type) / sizeof(char *) && table_type[i]) #ifdef HAVE_STRTOK_R ! table_type[++i] = strtok_r(NULL, ",", &last); #else ! table_type[++i] = strtok(NULL, ","); #endif /* HAVE_STRTOK_R */ ! /* Check for desired table types to return */ ! i = 0; ! while (table_type[i]) ! { ! UCHAR *typestr = (UCHAR *) table_type[i]; ! while (isspace(*typestr)) typestr++; if (*typestr == '\'') typestr++; --- 1719,1740 ---- #endif /* ODBCVER */ else { ! /* Check for desired table types to return */ ! char *srcstr; ! for (srcstr = tableType;; srcstr = NULL) ! { ! char *typestr; ! #ifdef HAVE_STRTOK_R ! typestr = strtok_r(srcstr, ",", &last); #else ! typestr = strtok(srcstr, ","); #endif /* HAVE_STRTOK_R */ ! if (typestr == NULL) ! break; ! while (isspace((unsigned char) *typestr)) typestr++; if (*typestr == '\'') typestr++; *************** *** 1743,1749 **** retry_public_schema: show_regular_tables = TRUE; else if (strnicmp(typestr, CSTR_VIEW, strlen(CSTR_VIEW)) == 0) show_views = TRUE; - i++; } } --- 1744,1749 ---- *************** *** 1761,1767 **** retry_public_schema: strcat(tables_query, " and relname !~ '^" POSTGRES_SYS_PREFIX); /* Also filter out user-defined system table types */ ! for (i = 0; prefix[i]; i++) { strcat(tables_query, "|^"); strcat(tables_query, prefix[i]); --- 1761,1767 ---- strcat(tables_query, " and relname !~ '^" POSTGRES_SYS_PREFIX); /* Also filter out user-defined system table types */ ! for (i = 0; i < nprefixes; i++) { strcat(tables_query, "|^"); strcat(tables_query, prefix[i]); *************** *** 1888,1895 **** retry_public_schema: else { /* Check extra system table prefixes */ ! i = 0; ! while (prefix[i]) { mylog("table_name='%s', prefix[%d]='%s'\n", table_name, i, prefix[i]); if (strncmp(table_name, prefix[i], strlen(prefix[i])) == 0) --- 1888,1894 ---- else { /* Check extra system table prefixes */ ! for (i = 0; i < nprefixes; i++) { mylog("table_name='%s', prefix[%d]='%s'\n", table_name, i, prefix[i]); if (strncmp(table_name, prefix[i], strlen(prefix[i])) == 0) *************** *** 1897,1903 **** retry_public_schema: systable = TRUE; break; } - i++; } } } --- 1896,1901 ----
^ permalink raw reply [nested|flat] 4+ messages in thread

* Re: Static analysis fix request
  2014-01-06 09:00 Static analysis fix request Pavel Raiskup <praiskup@redhat.com>
  2014-01-06 10:14 ` Re: Static analysis fix request Heikki Linnakangas <hlinnakangas@vmware.com>
@ 2014-01-06 14:48   ` Pavel Raiskup <praiskup@redhat.com>
  2014-01-07 14:04     ` Re: Static analysis fix request Heikki Linnakangas <hlinnakangas@vmware.com>
  0 siblings, 1 reply; 4+ messages in thread

From: Pavel Raiskup @ 2014-01-06 14:48 UTC (permalink / raw)
  To: Heikki Linnakangas <hlinnakangas@vmware.com>; +Cc: pgsql-odbc

> That code is really difficult to read, and hence difficult to get
> correct. Since we've already been burned twice by it, let's make it less
> error-prone. How about the attached? Does that look correct to you?

Thanks for looking at this, I don't see a problem in your patch; the code
should not change behavior (except not touching outside array borders).



-- 
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: Static analysis fix request
  2014-01-06 09:00 Static analysis fix request Pavel Raiskup <praiskup@redhat.com>
  2014-01-06 10:14 ` Re: Static analysis fix request Heikki Linnakangas <hlinnakangas@vmware.com>
  2014-01-06 14:48   ` Re: Static analysis fix request Pavel Raiskup <praiskup@redhat.com>
@ 2014-01-07 14:04     ` Heikki Linnakangas <hlinnakangas@vmware.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Heikki Linnakangas @ 2014-01-07 14:04 UTC (permalink / raw)
  To: Pavel Raiskup <praiskup@redhat.com>; +Cc: pgsql-odbc

On 01/06/2014 04:48 PM, Pavel Raiskup wrote:
>> That code is really difficult to read, and hence difficult to get
>> correct. Since we've already been burned twice by it, let's make it less
>> error-prone. How about the attached? Does that look correct to you?
>
> Thanks for looking at this, I don't see a problem in your patch; the code
> should not change behavior (except not touching outside array borders)

Ok, committed. Thanks!

- Heikki


-- 
Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-odbc



^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2014-01-07 14:04 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2014-01-06 09:00 Static analysis fix request Pavel Raiskup <praiskup@redhat.com>
2014-01-06 10:14 ` Heikki Linnakangas <hlinnakangas@vmware.com>
2014-01-06 14:48   ` Pavel Raiskup <praiskup@redhat.com>
2014-01-07 14:04     ` Heikki Linnakangas <hlinnakangas@vmware.com>

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