Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1YgHci-00025N-Hf for pgsql-odbc@arkaria.postgresql.org; Thu, 09 Apr 2015 18:56:20 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1YgHch-0002l4-Oa for pgsql-odbc@arkaria.postgresql.org; Thu, 09 Apr 2015 18:56:19 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:DHE_RSA_AES_256_CBC_SHA256:256) (Exim 4.80) (envelope-from ) id 1YgHcg-0002kt-Oa for pgsql-odbc@postgresql.org; Thu, 09 Apr 2015 18:56:18 +0000 Received: from mail-wi0-x22c.google.com ([2a00:1450:400c:c05::22c]) by makus.postgresql.org with esmtps (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.80) (envelope-from ) id 1YgHcc-0005PO-Cw for pgsql-odbc@postgresql.org; Thu, 09 Apr 2015 18:56:16 +0000 Received: by wizk4 with SMTP id k4so103394567wiz.1 for ; Thu, 09 Apr 2015 11:56:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:message-id:date:from:reply-to:user-agent:mime-version:to :subject:references:in-reply-to:content-type :content-transfer-encoding; bh=NXnyGg1PEBrGONQcZ8KI2oMdS/QzC4pJ3sk1w8y1idg=; b=bZVIszd7w6EUFAngDm+clrLvckdAumM7tXX2XPwRWhMSTilR7csjbViJAr15dN1YaY TVYpZcwcFuBn03RxdWNR+/Sh5FuPF/tM0W3AT4KtnOejbB3wvulsz/42PAcRbX51H8dO nGpWfiTTPdGT+3g+Opypomtnsej7triEV2NwGWklPJrAmUk6AU+y52OjK6XYrfrSbsEK kavQUM5ihqwYX6Ytmw476qXK4zmONx27R3n24zZ/rV6Gnk1LwoJrhZUSVfNptajpZpBF gPJSC1v24nivc9OkUSzy1LzzBjxt5zdpuTJwFF03pLrvZ3OeqlnIpebZYZJ44QU0d0n2 F/Ig== X-Received: by 10.194.133.199 with SMTP id pe7mr63788940wjb.120.1428605771676; Thu, 09 Apr 2015 11:56:11 -0700 (PDT) Received: from [192.168.1.99] (dsl-hkibrasgw1-58c38f-82.dhcp.inet.fi. [88.195.143.82]) by mx.google.com with ESMTPSA id z13sm21269837wjr.44.2015.04.09.11.56.10 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 09 Apr 2015 11:56:10 -0700 (PDT) Message-ID: <5526CB48.60606@iki.fi> Date: Thu, 09 Apr 2015 21:56:08 +0300 From: Heikki Linnakangas Reply-To: hlinnaka@iki.fi User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Icedove/31.5.0 MIME-Version: 1.0 To: Frank van der Aa - Vanboxtel BV , pgsql-odbc@postgresql.org Subject: Re: PGSQL ODBC driver crash in CC_get_current_schema References: <5524EBEE.2090603@vanboxtel.nl> In-Reply-To: <5524EBEE.2090603@vanboxtel.nl> Content-Type: text/plain; charset=windows-1252; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -2.3 (--) 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 04/08/2015 11:50 AM, Frank van der Aa - Vanboxtel BV wrote: > Hi, > > we are using the PostgreSQL 9.2.4 with ODBC driver 09.03.0400. > > We experience a driver crash when, for some reason (e.g. insufficient > permissions), there is no schema set. > > This happens because the strdup in the CC_get_current_schema function in > connection.c is executed while the 'select current_schema()' query > returned NULL. > > We have created a patch to workaround the strdup when the result of > QR_get_value_backend_text is NULL: > > # diff connection.c.orig connection.c > 4073c4073,4081 > < conn->current_schema = > strdup(QR_get_value_backend_text(res, 0, 0)); > --- > > { > > const char* value = > QR_get_value_backend_text(res, 0, 0); > > > > if (value == NULL) > > conn->current_schema = NULL; > > else > > conn->current_schema = strdup(value); > > > > } > > We have tested this patch in our environment and didn't experience any > problems. However, we don't oversee the entire code, but expect this not > to give any more problems. Hmm. That's not a very complete fix. Not all of the callers of CC_get_current_schema() check for a NULL, so you'll still get a segfault in the caller in some cases. Also, the NULL current_schema value should be cached like a valid value, otherwise the driver will call current_schema() repeatedly. Committed. I did those additional fixes, and added a test case to the regression suite. 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