credativ / informix_fdw

Foreign Data Wrapper for Informix Databases
Other
28 stars 5 forks source link

Insert Into Select Segfault #21

Closed ghost closed 5 years ago

ghost commented 6 years ago

This SQL example causes a segfault:

mydb=# \d mytable
                   Foreign table "public.mytable"
   Column    |            Type             | Modifiers | FDW Options
-------------+-----------------------------+-----------+-------------
 myint       | integer                     |           |
 mychar      | character(20)               |           |
 myvarchar   | character varying(20)       |           |
 mydate      | date                        |           |
 mytimestamp | timestamp without time zone |           |
Server: ol_informix1210
FDW Options: ("table" 'mytable', database 'mydb', client_locale 'en_us.utf8', db_locale 'en_us.819')

mydb=# CREATE TEMPORARY TABLE test1 AS SELECT * FROM mytable;
SELECT 1

mydb=# INSERT INTO mytable SELECT * FROM test1;
server closed the connection unexpectedly
  This probably means the server terminated abnormally
  before or while processing the request.
The connection to the server was lost. Attempting reset: Failed.

The extension was built with debug symbols and gdb gives me this stack trace:

#0  0x00000000007a3e30 in pg_detoast_datum_packed ()
#1  0x000000000077a422 in text_to_cstring ()
#2  0x00007fc358273c35 in ifxColumnValuesToSqlda (state=state@entry=0x2dc3428,
    slot=slot@entry=0x2d8a970, attnum=1) at ifx_fdw.c:1043
#3  0x00007fc358273e81 in ifxExecForeignInsert (estate=<optimized out>,
    rinfo=<optimized out>, slot=0x2d8a970, planSlot=<optimized out>)
    at ifx_fdw.c:1673
#4  0x00000000005ca237 in ExecModifyTable ()
#5  0x00000000005b2ab8 in ExecProcNode ()
#6  0x00000000005afc80 in standard_ExecutorRun ()
#7  0x00000000006b16fe in ProcessQuery ()
#8  0x00000000006b192d in PortalRunMulti ()
#9  0x00000000006b241d in PortalRun ()
#10 0x00000000006b01f3 in PostgresMain ()
#11 0x0000000000469585 in ServerLoop ()
#12 0x0000000000658ae9 in PostmasterMain ()
#13 0x000000000046a1ae in main ()
ghost commented 6 years ago

I believe the key to fixing this issue is to use the slot_getattr() function instead of accessing slot->tts_values directly.

https://doxygen.postgresql.org/heaptuple_8c_source.html#l01517 (slot_getattr source)