Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hdJws-0001md-R8 for pgsql-bugs@arkaria.postgresql.org; Tue, 18 Jun 2019 19:39:20 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hdJwr-0003fd-M7 for pgsql-bugs@arkaria.postgresql.org; Tue, 18 Jun 2019 19:39:17 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hdJpM-0004PU-W7 for pgsql-bugs@lists.postgresql.org; Tue, 18 Jun 2019 19:31:33 +0000 Received: from forward102p.mail.yandex.net ([77.88.28.102]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hdJpE-0007ug-Oa for pgsql-bugs@lists.postgresql.org; Tue, 18 Jun 2019 19:31:31 +0000 Received: from mxback1o.mail.yandex.net (mxback1o.mail.yandex.net [IPv6:2a02:6b8:0:1a2d::1b]) by forward102p.mail.yandex.net (Yandex) with ESMTP id 16BA11D418FE for ; Tue, 18 Jun 2019 22:31:21 +0300 (MSK) Received: from smtp1p.mail.yandex.net (smtp1p.mail.yandex.net [2a02:6b8:0:1472:2741:0:8b6:6]) by mxback1o.mail.yandex.net (nwsmtp/Yandex) with ESMTP id UPBr50yjYd-VKpmqn3M; Tue, 18 Jun 2019 22:31:21 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yandex.ru; s=mail; t=1560886281; bh=scS3xbE4cbIjNC9dazu+R5BG7amrtx+MJpM1U9Vm7KY=; h=Subject:From:To:Date:Message-ID; b=uQ3Skji+CexqQHZSWlQsc34F215ym98PWblmz4nIeksRW+8tc2cOOySEDxWBvjK4C cgdd9fSoX+GobDfcOlaP7cTep99xpHoXzkN90CUXMeVYWXEGpVeCy7yKFsQhTZraUm VN2+yyrgBbkmkoGckA8ASJmT3wXQ55P1/8l8BPkc= Authentication-Results: mxback1o.mail.yandex.net; dkim=pass header.i=@yandex.ru Received: by smtp1p.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id KWV5U7JtrN-VK9O82MY; Tue, 18 Jun 2019 22:31:20 +0300 (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) To: pgsql-bugs@lists.postgresql.org From: Werewolf Subject: ODBC: SQLGetDescField returns incorrect length for SQL_DESC_COUNT field of APD Message-ID: <1fe4d02c-9744-d02e-7cb4-76d259e01792@yandex.ru> Date: Tue, 18 Jun 2019 22:31:17 +0300 MIME-Version: 1.0 Content-Type: text/html; charset=utf-8 Content-Language: ru-RU Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Field SQL_DESC_COUNT should fit into a variable of type SQLSMALLINT. But when retrieving this field of APD SQLGetDescField returns SQLINTEGER value. So memory corruption is possible in application using psqlodbc driver.
Also the function returns an undefined error code -8.

The mistake is located here
https://git.postgresql.org/gitweb/?p=psqlodbc.git;a=blob;f=pgapi30.c;h=ba0dd6d731bbccd81392def43ae9b10e9c013aef;hb=HEAD#l1240

Just replace 'ret = SQL_IS_SMALLINT;' with 'rettype = SQL_IS_SMALLINT;'.