pg.ddx.io pgsql-odbc@postgresql.org mailing list archive
help / color / mirror / Atom feed From: Heikki Linnakangas <hlinnakangas@vmware.com>
To: Pavel Raiskup <praiskup@redhat.com>
Cc: psql-odbc <pgsql-odbc@postgresql.org>
Subject: Re: Static analysis fix request
Date: Mon, 06 Jan 2014 12:14:58 +0200
Message-ID: <52CA8222.4000208@vmware.com> (raw )
In-Reply-To: <38586059.r5Bu4hye1i@nb.usersys.redhat.com >
References: <38586059.r5Bu4hye1i@nb.usersys.redhat.com >
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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 ----
view thread (4+ messages) latest in thread
Message-ID: <52CA8222.4000208@vmware.com>
Permalink: ../52CA8222.4000208@vmware.com/
Also on: postgresql.org/message-id/52CA8222.4000208@vmware.com
copy link · copy postgr.es · copy git am
reply Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-odbc@postgresql.org
Cc: hlinnakangas@vmware.com, praiskup@redhat.com
Subject: Re: Static analysis fix request
In-Reply-To: <52CA8222.4000208@vmware.com>
References: <38586059.r5Bu4hye1i@nb.usersys.redhat.com> <52CA8222.4000208@vmware.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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