Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W1ODh-0005rG-FG for pgsql-odbc@arkaria.postgresql.org; Thu, 09 Jan 2014 22:36:57 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1W1ODg-0003Il-VY for pgsql-odbc@arkaria.postgresql.org; Thu, 09 Jan 2014 22:36:57 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W1ODg-0003Ie-2c for pgsql-odbc@postgresql.org; Thu, 09 Jan 2014 22:36:56 +0000 Received: from smtp-outbound-1.vmware.com ([208.91.2.12]) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1W1ODZ-0003yY-7B for pgsql-odbc@postgresql.org; Thu, 09 Jan 2014 22:36:55 +0000 Received: from sc9-mailhost3.vmware.com (sc9-mailhost3.vmware.com [10.113.161.73]) by smtp-outbound-1.vmware.com (Postfix) with ESMTP id 33E4B28737; Thu, 9 Jan 2014 14:36:47 -0800 (PST) Received: from zcs-prod-ext-mta-2.vmware.com (zcs-prod-ext-mta-2.vmware.com [10.113.62.224]) by sc9-mailhost3.vmware.com (Postfix) with ESMTP id 2C344403BE; Thu, 9 Jan 2014 14:36:47 -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 E684EC0053; Thu, 9 Jan 2014 14:37:20 -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; Thu, 9 Jan 2014 14:37:20 -0800 (PST) Message-ID: <52CF247C.5030303@vmware.com> Date: Fri, 10 Jan 2014 00:36:44 +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: Patrice Dardoize CC: pgsql-odbc@postgresql.org Subject: Re: buffer overwrite in function BuildBindRequest (file convert.c line 3749) References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -6.9 (------) 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 On 01/09/2014 04:04 PM, Patrice Dardoize wrote: > Hello, > > I'm using odbc driver version 9.3.1.0 for PostgreSQL. > > I'm trying to insert a new row in a table containing 3 columns (integer, > varying character (150) and bytea). > > Depending on the data size transfered to the bytea column, I experience a > buffer overwrite (memory written at the very end of memory allocated for > variable qb.query_statement). > > After having downloaded the latest available source code and compiled the > odbc driver (under Visual Studio 2010), I found out that a problem may > occur in function BuildBindRequest (from file convert.c line 3749) when > appending a terminating 0 (Int2) at the end of qb.query_statement. > > The memory actually allocated for this buffered (for which the size is > stored in qb.str_alsize as I could understand) may be insufficient to > contain the Int2. Yep, good catch. > I've just added a call to ENLARGE_NEWSTATEMENT to fix > the problem : > > leng = qb.npos; > ENLARGE_NEWSTATEMENT((&qb), leng + sizeof(Int2)); /* this line was > added to correct the buffer overwrite */ > memset(qb.query_statement + leng, 0, sizeof(Int2)); /* result > format is text */ > leng += sizeof(Int2); That's not 100% correct, ENLARGE_NEWSTATEMENT will not do the right thing in this function if the allocation fails. But I committed a fix along those lines. > In order to reproduce the issue, you may simply try to insert a new row > containing : > - an arbitrary int value for the first column > - NULL for the second column > - any binary content of 8132 bytes length I also added a test case to the regression test suite that does something like that. Thanks for the report! - Heikki -- Sent via pgsql-odbc mailing list (pgsql-odbc@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-odbc