Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W07DJ-0005H7-G8 for pgsql-odbc@arkaria.postgresql.org; Mon, 06 Jan 2014 10:15:17 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1W07DI-0007he-AT for pgsql-odbc@arkaria.postgresql.org; Mon, 06 Jan 2014 10:15:16 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W07DH-0007gW-BF for pgsql-odbc@postgresql.org; Mon, 06 Jan 2014 10:15:15 +0000 Received: from smtp-outbound-2.vmware.com ([208.91.2.13]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W07D7-0002qO-Jt for pgsql-odbc@postgresql.org; Mon, 06 Jan 2014 10:15:13 +0000 Received: from sc9-mailhost2.vmware.com (sc9-mailhost2.vmware.com [10.113.161.72]) by smtp-outbound-2.vmware.com (Postfix) with ESMTP id A299828279; Mon, 6 Jan 2014 02:15:01 -0800 (PST) Received: from zcs-prod-ext-mta-2.vmware.com (zcs-prod-ext-mta-2.vmware.com [10.113.62.224]) by sc9-mailhost2.vmware.com (Postfix) with ESMTP id 7EADEB043E; Mon, 6 Jan 2014 02:15:01 -0800 (PST) Received: from zcs-prod-ext-mta-2.vmware.com (localhost.localdomain [127.0.0.1]) by zcs-prod-ext-mta-2.vmware.com (Postfix) with ESMTP id 1ACC1C0060; Mon, 6 Jan 2014 02:15:34 -0800 (PST) Received: from [192.168.1.90] (zimbra-prod-ext-proxy-vip.vmware.com [10.113.63.87]) by zcs-prod-ext-mta-2.vmware.com (Postfix) with ESMTPSA; Mon, 6 Jan 2014 02:15:32 -0800 (PST) Message-ID: <52CA8222.4000208@vmware.com> Date: Mon, 06 Jan 2014 12:14:58 +0200 From: Heikki Linnakangas Organization: VMware User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131005 Icedove/17.0.9 MIME-Version: 1.0 To: Pavel Raiskup CC: psql-odbc Subject: Re: Static analysis fix request References: <38586059.r5Bu4hye1i@nb.usersys.redhat.com> In-Reply-To: <38586059.r5Bu4hye1i@nb.usersys.redhat.com> Content-Type: multipart/mixed; boundary="------------090407080603020504040906" X-Pg-Spam-Score: -7.2 (-------) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-odbc Precedence: bulk Sender: pgsql-odbc-owner@postgresql.org This is a multi-part message in MIME format. --------------090407080603020504040906 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 --------------090407080603020504040906 Content-Type: text/x-diff; name="fix-prefixes-and-table_types-loops-2.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="fix-prefixes-and-table_types-loops-2.patch" *** 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 ---- --------------090407080603020504040906 Content-Type: text/plain Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 -- Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-odbc --------------090407080603020504040906--