Re: Returning non-terminated string in ECPG Informix-compatible function

From: Oleg Tselebrovskiy <o(dot)tselebrovskiy(at)postgrespro(dot)ru>
To: Ashutosh Bapat <ashutosh(dot)bapat(dot)oss(at)gmail(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Returning non-terminated string in ECPG Informix-compatible function
Date: 2024-01-30 10:56:22
Message-ID: 4ab77531d15e9234ea4615dd8501078d@postgrespro.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message David Rowley 2024-01-30 11:00:05 Re: Some revises in adding sorting path
Previous Message jian he 2024-01-30 10:50:00 Re: MERGE ... RETURNING