Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gEKYt-0005tz-6E for pgsql-odbc@arkaria.postgresql.org; Sun, 21 Oct 2018 20:42:59 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1gEKYq-0008MN-Uk for pgsql-odbc@arkaria.postgresql.org; Sun, 21 Oct 2018 20:42:56 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1gEKYq-0008MG-Lh for pgsql-odbc@lists.postgresql.org; Sun, 21 Oct 2018 20:42:56 +0000 Received: from mail-lf1-f52.google.com ([209.85.167.52]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1gEKYh-0004GI-N6 for pgsql-odbc@postgresql.org; Sun, 21 Oct 2018 20:42:54 +0000 Received: by mail-lf1-f52.google.com with SMTP id n3-v6so1923059lfe.7 for ; Sun, 21 Oct 2018 13:42:47 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=QNJwxRcX1TmZJJwfiB71T7zREXIOBT0nQedei0wW5cI=; b=fElvJYSoR8/LoCp4CDzbLaKYMbsb6WkCuRXGKWgQzobf/MOvvmzRI/IhMzuLiyRtmX T8Bsr+vzMc5nl+kGStg4PgEe99EZTEIdsjYVPK1O4GHcg6FmFNyg+Qr5kGtGQlItK7hv YuHX0zUQN6fFtdRyUgtXyItnHwO0iKN5wBEcJ6KHwYc012yGumLykjsvCPu8Bj8K8FyV Zn+uBSWBJVh4aRXVrrhEE2eDFhUda+hUwhMJQtn8fh8gNFPbwgKGEwrJ3pIAGbHl9UuV lM9DjYRdwCK0eHtDrtoPhb3pHg1ayEM5hlXULMSZwRb9JUPCGZA0zhQi1Yq8XXocp4zJ Hu6g== X-Gm-Message-State: ABuFfoiqD6P5CK8LmARH4G6D3/fYgbu8YmIC/9t725EM8TmyuGLEIw2Z I3K1pH0lx6lLG0D3IlTCGrriJPfp X-Google-Smtp-Source: ACcGV633Rw/qxWkXZr5qrpbz1CoJXZrP83MiJK6cwXRh3JymiXVg20CW8FWwGlyQGQAoierQFtAbFw== X-Received: by 2002:a19:3bcf:: with SMTP id d76-v6mr7423534lfl.126.1540154564749; Sun, 21 Oct 2018 13:42:44 -0700 (PDT) Received: from [192.168.1.11] (dsl-hkibng32-54fbf8-78.dhcp.inet.fi. [84.251.248.78]) by smtp.gmail.com with ESMTPSA id h203-v6sm6481019lfg.7.2018.10.21.13.42.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 21 Oct 2018 13:42:43 -0700 (PDT) Subject: Re: Crash in 64 bit ODBC driver when using bookmarks To: Paal Christof , "pgsql-odbc@postgresql.org" References: <168ee54f5e0044088c596bc88bcc335e@NRDW2EX3.NR.NC3A> From: Heikki Linnakangas Message-ID: <63d13cfb-3b15-c3ca-14ae-adabaec1b4df@iki.fi> Date: Sun, 21 Oct 2018 23:42:37 +0300 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 In-Reply-To: <168ee54f5e0044088c596bc88bcc335e@NRDW2EX3.NR.NC3A> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 19/10/2018 15:16, Paal Christof wrote: > I think I have found a bug in the PostgreSQL ODBC driver (of which I am using the latest version 10_03). > I am using SQLBindCol to bind a bookmark column of type SQL_C_VARBOOKMARK. > > Everything works perfectly when I compile my application in 32 bit mode and use the 32 bit ODBC driver. > With the 64 bit driver I get an instant crash (memory exception). > With logging turned on, the last entry in the mylog is the following: > [SC_Create_bookmark]3133: entering type=-2 buflen=64 buf=000000000C6AF268 > > I can also attach a debugger and the crash happens at the following line: > memcpy(CALC_BOOKMARK_ADDR(bookmark, offset, bind_size, bind_row), &pg_bm, cvtlen); > > At that time the value of the bookmark variable is: bookmark = 0x0000000000000001 {buflen=??? buffer=??? used=??? ...}, screenshot attached. > Although it received good values when the function was called (as seen in the log), the memory got corrupted in between and it is no longer a valid pointer. > I assume this is because something is writing a 64 bit value into a buffer which is only made for a 32 bit integer. Can you provide a self-contained test case? There is a test case that uses SQLBindCol with SQL_C_VARBOOKMARK, in the regression test suite, and it's been working fine: https://git.postgresql.org/gitweb/?p=psqlodbc.git;a=blob;f=test/src/bookmark-test.c;h=ccdfa5e8428900bae4264c581774a8c6c2d34b80;hb=HEAD#l108 If you could reproduce the crash with some changes to that test program, that would help a lot. - Heikki