mridoni / gixsql

GixSQL is an ESQL preprocessor and a series of runtime libraries to enable GnuCOBOL to access PostgreSQL, ODBC, MySQL, Oracle and SQLite databases.
GNU General Public License v3.0
16 stars 8 forks source link

gixpp 1.0.17 SIGSEGVs #93

Closed GitMensch closed 2 years ago

GitMensch commented 2 years ago

While previous versions could compile this source, 1.017 can't. The offending part seems to be the VARYING definition.

Program received signal SIGSEGV, Segmentation fault.
0x000000000046b8d9 in gethostvarianttype (p=0x0, type=0x7fffffffa98c) at ../../libgixpp/TPESQLProcessing.cpp:1656
1656            if (p->pictype != 0) {
(gdb) bt
#0  0x000000000046b8d9 in gethostvarianttype (p=0x0, type=0x7fffffffa98c) at ../../libgixpp/TPESQLProcessing.cpp:1656
#1  0x000000000046be36 in TPESQLProcessing::get_actual_field_data (this=0x73ec60, f=0x74c590, type=0x7fffffffa98c, size=0x7fffffffa988, scale=0x7fffffffa984) at ../../libgixpp/TPESQLProcessing.cpp:1850
#2  0x0000000000485ad7 in gix_esql_driver::cb_host_list_add (this=0x73ed00, list=0x771c30, text=...) at ../../libgixpp/gix_esql_driver.cc:208
#3  0x000000000048f639 in yy::gix_esql_parser::parse (this=0x7fffffffb850) at gix_esql_parser.yy:758
#4  0x00000000004851d1 in gix_esql_driver::parse (this=0x73ed00, gpp=0x7fffffffc2b0, f=...) at ../../libgixpp/gix_esql_driver.cc:112
#5  0x000000000045f8e9 in TPESQLProcessing::run (this=0x73ec60, prev_step=0x0) at ../../libgixpp/TPESQLProcessing.cpp:294
#6  0x000000000045a8fa in GixPreProcessor::transform (this=0x7fffffffc2b0) at ../../libgixpp/GixPreProcessor.cpp:138
#7  0x000000000045a710 in GixPreProcessor::process (this=0x7fffffffc2b0) at ../../libgixpp/GixPreProcessor.cpp:129
#8  0x000000000040b643 in main (argc=8, argv=0x7fffffffc9f8) at ../../gixpp/main.cpp:163

The problem is at frame 2:

1849                    cb_field_ptr f_actual = main_module_driver.field_map[f_actual_name];
1850                    gethostvarianttype(f_actual, type);

in line 1849 main_module_driver.field_map[f_actual_name] does not provide a return and gethostvarianttype() in the next line reasonably expects a non-null parameter.

(gdb) p f->sname.c_str()
$1 = 0x74c5a0 "BUFFER"
(gdb) p f_actual_name.c_str()
$2 = 0x7fffffffa8c0 "BUFFER-ARR"

and gixpp is currently adding a token

754     token_list:
755     expr                            {      $$ = driver.cb_text_list_add (NULL, $1);}
756     | token_list expr       {      $$ = driver.cb_text_list_add ($1, $2);}
757     | token_list host_reference   {
758             $$ = driver.cb_text_list_add ($1, driver.cb_host_list_add (driver.host_reference_list, $2));
759     }

variable is defined and referenced as:

 01 BUFFER                   PIC X(500000) VARYING.
mridoni commented 2 years ago

I stumbled into this while I was working on the (misguided) attempt to solve the VARCHAR2 issue. As a quick fix, the following two patches might/should solve the issue.

GitMensch commented 2 years ago

This does preprocess now (changing the gix_esql_parser.cc additional, as there's not a recent enough bison available on that machine) - can't actually test if it is working now, maybe next week.

GitMensch commented 2 years ago

solved with 1.0.18.dev1