Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rUln2-00CvjN-Gb for pgsql-hackers@arkaria.postgresql.org; Tue, 30 Jan 2024 10:56:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1rUln1-004Tse-A1 for pgsql-hackers@arkaria.postgresql.org; Tue, 30 Jan 2024 10:56:27 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rUln0-004TsW-S6 for pgsql-hackers@lists.postgresql.org; Tue, 30 Jan 2024 10:56:27 +0000 Received: from mail.postgrespro.ru ([93.174.131.139]) by magus.postgresql.org with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1rUlmy-004Vfm-FA for pgsql-hackers@postgresql.org; Tue, 30 Jan 2024 10:56:25 +0000 Received: from mail.postgrespro.ru (webmail.mstn.postgrespro.ru [192.168.2.26]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client did not present a certificate) (Authenticated sender: o.tselebrovskiy@postgrespro.ru) by mail.postgrespro.ru (Postfix/587) with ESMTPSA id C3D78E20E3B; Tue, 30 Jan 2024 13:56:22 +0300 (MSK) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=postgrespro.ru; s=mx2023; t=1706612182; bh=OD4Iwf1UKqZc/2mnq9SOyy8yyHRVMUVPV+S22upzlS4=; h=Date:From:To:Cc:Subject:In-Reply-To:References:User-Agent: Message-ID:From; b=Wg6p1mSxTkqxoEWhi19RhljvyDy799J2Cd9qgsNafhl+bIpbR/08YTmPXuzrHc6Os HjtRBrd+JRwQ9lc+jrZF856VWeoqIG9hf6fG32WjdhRFrfyOlyJKjQD78DRdm1ARmh 2ERpA2+78ESMgLNqzxkUizj54AovvATVz8u5P/FNAd2y9wK+9IciP4k250SAUL3BF1 tdyHVS4lPmFgyevwvJYGgTzpPraiCb3MS0Zoukam7gyQ+eAGBuWh9N6WCcvyEPPFTw IQUCDJwMlNxRmZKFp6a8XPeP3MJWeJKGFmGkldHbQKjBs3844ZV0/gORue/8uMMqM3 BVtan4kmcHMZg== MIME-Version: 1.0 Date: Tue, 30 Jan 2024 13:56:22 +0300 From: Oleg Tselebrovskiy To: Ashutosh Bapat Cc: pgsql-hackers@postgresql.org Subject: Re: Returning non-terminated string in ECPG Informix-compatible function In-Reply-To: References: User-Agent: Roundcube Webmail/1.6.5 Message-ID: <4ab77531d15e9234ea4615dd8501078d@postgrespro.ru> X-Sender: o.tselebrovskiy@postgrespro.ru Organization: Postgres Pro Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Here's the code for bug reproduction: #include #include EXEC SQL INCLUDE pgtypes_interval.h; EXEC SQL INCLUDE ecpg_informix.h; EXEC SQL BEGIN DECLARE SECTION; char dirty_str[100] = "aaaaaaaaa_bbbbbbbb_ccccccccc_ddddddddd_"; interval *interval_ptr; EXEC SQL END DECLARE SECTION; int main() { interval_ptr = (interval *) malloc(sizeof(interval)); interval_ptr->time = 100000000; interval_ptr->month = 240; printf("dirty_str contents before intoasc: %s\n", dirty_str); intoasc(interval_ptr, dirty_str); printf("dirty_str contents after intoasc: %s\n", dirty_str); return 0; } And here's the output: dirty_str contents before intoasc: aaaaaaaaa_bbbbbbbb_ccccccccc_ddddddddd_ dirty_str contents after intoasc: @ 20 years 1 min 40 secscccc_ddddddddd_ I compiled it with following commands (provided for quicker reproduction): /path/to/pgsql/bin/ecpg informix_bug_example.pgc gcc -I/path/to/pgsql/include -c informix_bug_example.c gcc -o informix_bug_example informix_bug_example.o -L/path/to/pgsql/lib -lecpg -lecpg_compat I've also found at least one project that uses intoasc() in it - https://github.com/credativ/informix_fdw/ Oleg Tselebrovskiy, Postgres Pro