public inbox for [email protected]  
help / color / mirror / Atom feed
From: Oleg Tselebrovskiy <[email protected]>
To: Ashutosh Bapat <[email protected]>
Cc: [email protected]
Subject: Re: Returning non-terminated string in ECPG Informix-compatible function
Date: Tue, 30 Jan 2024 13:56:22 +0300
Message-ID: <[email protected]> (raw)
In-Reply-To: <CAExHW5u-cBgFJLPHzjDSdOy2QA9wJRireaYCngVQqqC5oGxhOA@mail.gmail.com>
References: <[email protected]>
	<CAExHW5u-cBgFJLPHzjDSdOy2QA9wJRireaYCngVQqqC5oGxhOA@mail.gmail.com>

Here's the code for bug reproduction:
#include <stdio.h>
#include <stdlib.h>

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





view thread (3+ messages)

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: Returning non-terminated string in ECPG Informix-compatible function
  In-Reply-To: <[email protected]>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox