Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jqJGx-0003JS-QX for pgsql-bugs@arkaria.postgresql.org; Tue, 30 Jun 2020 16:38:15 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1jqJGw-0007wh-Ns for pgsql-bugs@arkaria.postgresql.org; Tue, 30 Jun 2020 16:38:14 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jqJGw-0007wZ-Hq for pgsql-bugs@lists.postgresql.org; Tue, 30 Jun 2020 16:38:14 +0000 Received: from mout.kundenserver.de ([212.227.17.13]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1jqJGu-0002Iq-F5 for pgsql-bugs@lists.postgresql.org; Tue, 30 Jun 2020 16:38:14 +0000 Received: from feivel.credativ.lan ([79.193.220.250]) by mrelayeu.kundenserver.de (mreue109 [212.227.15.183]) with ESMTPSA (Nemesis) id 1MV6G0-1jQMOD1XnC-00S7JG for ; Tue, 30 Jun 2020 18:38:11 +0200 Received: from localhost (localhost [127.0.0.1]) by feivel.credativ.lan (Postfix) with ESMTP id 4B9ADE00B7 for ; Tue, 30 Jun 2020 18:38:08 +0200 (CEST) Message-ID: <1451a00a0706d2f25fbcb580f6aef1e29c5b80a9.camel@postgresql.org> Subject: Re: [BUG][PATCH] ecpg crash with bytea type and cursors From: Michael Meskes To: pgsql-bugs@lists.postgresql.org Date: Tue, 30 Jun 2020 18:38:08 +0200 In-Reply-To: <20200630153008.3e73d3da@firost> References: <20200630153008.3e73d3da@firost> Organization: PostgreSQL Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.3-1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Provags-ID: V03:K1:5EczCUGQJIEFp2x/zuLIyHJ8Z5iT/hUtAJBBmtl/BMeMqeSxPhz dcrw8Bjb2P6iPbpNNzkF59zweXukcqWdeg6RUqSKypEwa7Na6ZvGcZCArmHFk4W0ODoOG76 VrKVRIxsaEz9U69Yuk0I8n7YpZFe5wrkomXYoZ4VglSylStC9arnExmrg338bv3P1TxsOb5 T/woL2o9bnCdORzPOJAAQ== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:vPL9eiQl3tE=:8g30squqjCu/mFmCHGTVjq vD18g+znKt+sVtQlv/LEKViJQvuDP69kDotTivlkfXNUxW9yjRxKy42hJ0iXDyyVZId8DiYyc bcBczOwkK84vxMurlqdbZpLUQOAEN35msFmpNAafaRcLiqZYeLRSly0VzOzEovxzIGVWJIJqZ RWh118st8gPSQuamh3QaOnqv2Y4C3VUMvXbiS6o9tBRWkT3c5oMBYdtofHFU+a2ZOpXuUqzot tuuVIxsk7e5STXKPQ+/ZM1y7ZW21n+vPs+kSQc4IiDj6My5Ri4hUkF15xu+i5vY/BbDpY0Ij8 j2hxB2/Iw2+2J292WsSmKDssAa6pAJKb0zmRDL6a0NyPeI0/V37v0sltDK6GFf0Y26q0HBpmF KTOO0tiD2M39SrdHQ6+GRxM7BKRUtfh0iOTuXxNMXghVnPMQH9rEseBw/VsxEDEzehKOWiuZO vRAJPRHlWKiZtY/EV4bpLIGMo+FFYFIlHTIuXqaZMq8HGRJasDMr6aHdthvSOWuNhVlX2F3Zn ChPoIPLcEsNnScdkM20RrWQG6ohzV+ow/D73zYVxt+wcq6oXCQUahJjvgxW4kVg26YdOglad4 xSmoWt5gNishwtUr2VNxAAYf5Acl26UiXeeR5aZCAdN6StdUwDNqSv2y6+uaEtIizonbtge8t 61bJf6GgOi3g0O6MBdZOlMX0rTEtF/kX4TxNK6bOd7s3ppUg39GFFVnxQhZQD5VxACNfAJJff yCoRWyYs/kh+RY1HplhelBw8p16BHLnYgPbSLdiT+5l4C/BIWPOh1SC/fBkPk2uGZbW1N+Wah 7/kI6j+sSDSsWq2aoxnTwOXQPHYza/LbaFaZOGHDli5x3SKEkIbl3jjF2KEo3y3Wm9Ky9/e List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Hi, On Tue, 2020-06-30 at 15:30 +0200, Jehan-Guillaume de Rorthais wrote: > ... > According to documentation and source, the bytea type is supposed to > be handled > as the varchar type. However, the original patch 050710b3696 miss to > add to > adjust_outofscope_cursor_vars() how to handle bytea type as variable. > Because of > this, bytea type was considered as an array of value, leading to the > crash > because type->u.element was all NULL. The patch adjust existing code > to > considers bytea in the same way varchar is handled. See in attachment > patch > v1-0002-Fix-ecpg-crash-with-bytea-and-cursor-variables.patch Thanks for finding and fixing this. Patch committed. > But there's something else the patch does not address and that might > need to be > adjusted. Existing tests were OK because they don't use cursors AND > bytea vars > are declared using a macro to hold their size. Eg.: > > bytea send_buf[2][DATA_SIZE]; # ok > bytea send_buf[2][512]; # crash ! > > This is because of this test in adjust_outofscope_cursor_vars() > (before the > proposed patch): > > else if ((ptr->variable->type->type != ECPGt_varchar > && ptr->variable->type->type != ECPGt_char > && ptr->variable->type->type != ECPGt_unsigned_char > && ptr->variable->type->type != ECPGt_string) > && atoi(ptr->variable->type->size) > 1) > > This test match and related code crash when the size is given as > number because > atoi(size) > 1. When using a macro to hold the size, this test > doesn't > match and the fallback else{} code doesn't crash, but it doesn't > build the same > variable neither (see indirection before ECPGget_var). I'm not sure > how > important it is for bytea/varchar type though. I don't know how to > build a test > case producing ECPGget_var for them. I try to find some time to look into this. Thanks again, Michael -- Michael Meskes Michael at Fam-Meskes dot De, Michael at Meskes dot (De|Com|Net|Org) Meskes at (Debian|Postgresql) dot Org Jabber: michael at xmpp dot meskes dot org VfL Borussia! Força Barça! SF 49ers! Use Debian GNU/Linux, PostgreSQL