Segmentation fault in SQLDriverConnect
Hey there! First, thanks for making this library. It's been an incredibly big help and I'm impressed with its quality. You're a great maintainer. I ran into a null pointer dereference today. Here is the stack trace:
SIGSEGV: segmentation violation
PC=0x7faf59adf0da m=21 sigcode=128 addr=0x0
signal arrived during cgo execution
goroutine 1027091 gp=0xc002b01dc0 m=21 mp=0xc000581808 [syscall]:
runtime.cgocall(0x74aad0, 0xc0097bb7d0)
/home/liam/go/pkg/mod/golang.org/[email protected]/src/runtime/cgocall.go:157 +0x4b fp=0xc0097bb7a8 sp=0xc0097bb770 pc=0x40746b
github.com/alexbrainman/odbc/api._Cfunc_SQLDriverConnectW(0x7faefc027e40, 0x0, 0xc00397c000, 0xfffd, 0x0, 0x0, 0x0, 0x0)
_cgo_gotypes.go:327 +0x4a fp=0xc0097bb7d0 sp=0xc0097bb7a8 pc=0x71208a
github.com/alexbrainman/odbc.(*Driver).Open.SQLDriverConnect.func2(0x7faefc027e40, 0xc0000b6090?, 0xc00397c000, 0xfffd, 0x0, 0x0, 0x0, 0x0)
/home/liam/go/pkg/mod/github.com/alexbrainman/[email protected]/api/zapi_unix.go:64 +0xd3 fp=0xc0097bb830 sp=0xc0097bb7d0 pc=0x715233
github.com/alexbrainman/odbc/api.SQLDriverConnect(...)
/home/liam/go/pkg/mod/github.com/alexbrainman/[email protected]/api/zapi_unix.go:64
github.com/alexbrainman/odbc.(*Driver).Open(0xb2bd60, {0xc00026c000, 0x8d})
/home/liam/go/pkg/mod/github.com/alexbrainman/[email protected]/conn.go:40 +0x13b fp=0xc0097bb980 sp=0xc0097bb830 pc=0x714e5b
database/sql.dsnConnector.Connect(...)
/home/liam/go/pkg/mod/golang.org/[email protected]/src/database/sql/sql.go:791
database/sql.(*dsnConnector).Connect(0xb464a0?, {0x7faf3c796e28?, 0x0?})
<autogenerated>:1 +0x31 fp=0xc0097bb9a8 sp=0xc0097bb980 pc=0x507b31
database/sql.(*DB).conn(0xc0001a5380, {0x8a6770, 0xb8cf40}, 0x1)
/home/liam/go/pkg/mod/golang.org/[email protected]/src/database/sql/sql.go:1415 +0x71e fp=0xc0097bbb30 sp=0xc0097bb9a8 pc=0x500e5e
database/sql.(*DB).query(0xc0001a5380, {0x8a6770, 0xb8cf40}, {0xc09d182000, 0x6586d}, {0x0, 0x0, 0x0}, 0x50?)
/home/liam/go/pkg/mod/golang.org/[email protected]/src/database/sql/sql.go:1749 +0x57 fp=0xc0097bbba8 sp=0xc0097bbb30 pc=0x502db7
database/sql.(*DB).QueryContext.func1(0x7b?)
/home/liam/go/pkg/mod/golang.org/[email protected]/src/database/sql/sql.go:1732 +0x4f fp=0xc0097bbc10 sp=0xc0097bbba8 pc=0x502cef
database/sql.(*DB).retry(0xb8e3c0?, 0xc0097bbc80)
/home/liam/go/pkg/mod/golang.org/[email protected]/src/database/sql/sql.go:1566 +0x42 fp=0xc0097bbc58 sp=0xc0097bbc10 pc=0x501c42
database/sql.(*DB).QueryContext(0x66000?, {0x8a6770?, 0xb8cf40?}, {0xc09d182000?, 0xc0097bbd30?}, {0x0?, 0xac25c0?, 0xc0097bbd98?})
/home/liam/go/pkg/mod/golang.org/[email protected]/src/database/sql/sql.go:1731 +0xc5 fp=0xc0097bbce8 sp=0xc0097bbc58 pc=0x502c05
database/sql.(*DB).Query(...)
/home/liam/go/pkg/mod/golang.org/[email protected]/src/database/sql/sql.go:1745
github.com/jmoiron/sqlx.(*DB).Queryx(0xc000256510, {0xc09d182000?, 0x4da45a?}, {0x0?, 0xc084b72000?, 0x6586d?})
/home/liam/go/pkg/mod/github.com/jmoiron/[email protected]/sqlx.go:352 +0x4c fp=0xc0097bbd50 sp=0xc0097bbce8 pc=0x5250ec
github.com/jmoiron/sqlx.Select({0x8a5d90?, 0xc000256510?}, {0x773cc0, 0xc060bdc348}, {0xc09d182000?, 0x66000000000001f4?}, {0x0?, 0x1b?, 0xc03577a600?})
/home/liam/go/pkg/mod/github.com/jmoiron/[email protected]/sqlx.go:677 +0x66 fp=0xc0097bbdc0 sp=0xc0097bbd50 pc=0x525866
github.com/jmoiron/sqlx.(*DB).Select(...)
/home/liam/go/pkg/mod/github.com/jmoiron/[email protected]/sqlx.go:320
I've been using the same version of this package with the same version of Go for weeks without issue. So unfortunately getting some concrete steps to reproduce it is quite difficult... I don't expect that this is enough to really solve it, but if anyone could point me in the right direction regarding my configuration below, that would be very appreciated.
There are three existing issues that refer to "segmentation fault":
- https://github.com/alexbrainman/odbc/issues/190 - this one has a different address and is not a null pointer dereference
- https://github.com/alexbrainman/odbc/issues/138 - this is in _Cfunc_SQLDriverConnectW, but I'm not sure if it's the same. There wasn't a whole lot of info there.
- https://github.com/alexbrainman/odbc/issues/139 - this actually might be the same, but it seems like in this person's case, it happened every time that call was made. I am only experiencing this very rarely.
go version go1.22.6 linux/amd64
Contents of /etc/odbcinst.ini:
[ODBC Drivers]
IBM INFORMIX ODBC DRIVER=Installed
[IBM INFORMIX ODBC DRIVER]
Driver=/opt/informix-csdk/lib/cli/iclis09b.so
Setup=/opt/informix-csdk/lib/cli/iclis09b.so
APILevel=1
ConnectFunctions=YYY
DriverODBCVer=03.51
FileUsage=0
SQLLevel=1
And /etc/odbc.ini:
[my_server]
DRIVER=/opt/informix-csdk/lib/cli/iclis09b.so
DESCRIPTION=Informix
DATABASE=sysmaster
LOGONID=some_user
pwd=some_password
SERVER=some_server
TRANSLATIONDLL=/opt/informix-csdk/lib/esql/igo4a304.so
DB_LOCALE=en_us.819
;
; UNICODE connection Section
;
[ODBC]
;uncomment the below line for UNICODE connection
UNICODE=UCS-2
;
; Trace file Section
;
TRACE=1
TRACEFILE=/tmp/odbctrace.out
INSTALLDIR=/opt/informix-csdk
TRACEDLL=idmrs09a.so
I have tracing enabled. Here is what I believe is the relevant entry:
ppid=002aa62d,pid=00000000 ENTER 2024-10-28 19:26:41 SQLDriverConnectW
SQLHDBC 0x7FAEFC011830
SQLHWND 0000
SQLWCHAR *****
SQLSMALLINT -3
SQLWCHAR * (null)
SQLSMALLINT 0
SQLSMALLINT * 0x7FAF59B526C0
SQLUSMALLINT 0
Thank you again for such a great library, and for your time.
Hello @hut8 ,
I don't use Informix myself. I don't have any good suggestions for you to try.
Alex
Hey there! First, thanks for making this library. It's been an incredibly big help and I'm impressed with its quality. You're a great maintainer. I ran into a null pointer dereference today. Here is the stack trace:
SIGSEGV: segmentation violation PC=0x7faf59adf0da m=21 sigcode=128 addr=0x0 signal arrived during cgo execution goroutine 1027091 gp=0xc002b01dc0 m=21 mp=0xc000581808 [syscall]: runtime.cgocall(0x74aad0, 0xc0097bb7d0) /home/liam/go/pkg/mod/golang.org/[email protected]/src/runtime/cgocall.go:157 +0x4b fp=0xc0097bb7a8 sp=0xc0097bb770 pc=0x40746b github.com/alexbrainman/odbc/api._Cfunc_SQLDriverConnectW(0x7faefc027e40, 0x0, 0xc00397c000, 0xfffd, 0x0, 0x0, 0x0, 0x0) _cgo_gotypes.go:327 +0x4a fp=0xc0097bb7d0 sp=0xc0097bb7a8 pc=0x71208a github.com/alexbrainman/odbc.(*Driver).Open.SQLDriverConnect.func2(0x7faefc027e40, 0xc0000b6090?, 0xc00397c000, 0xfffd, 0x0, 0x0, 0x0, 0x0) /home/liam/go/pkg/mod/github.com/alexbrainman/[email protected]/api/zapi_unix.go:64 +0xd3 fp=0xc0097bb830 sp=0xc0097bb7d0 pc=0x715233 github.com/alexbrainman/odbc/api.SQLDriverConnect(...) /home/liam/go/pkg/mod/github.com/alexbrainman/[email protected]/api/zapi_unix.go:64 github.com/alexbrainman/odbc.(*Driver).Open(0xb2bd60, {0xc00026c000, 0x8d}) /home/liam/go/pkg/mod/github.com/alexbrainman/[email protected]/conn.go:40 +0x13b fp=0xc0097bb980 sp=0xc0097bb830 pc=0x714e5b database/sql.dsnConnector.Connect(...) /home/liam/go/pkg/mod/golang.org/[email protected]/src/database/sql/sql.go:791 database/sql.(*dsnConnector).Connect(0xb464a0?, {0x7faf3c796e28?, 0x0?}) <autogenerated>:1 +0x31 fp=0xc0097bb9a8 sp=0xc0097bb980 pc=0x507b31 database/sql.(*DB).conn(0xc0001a5380, {0x8a6770, 0xb8cf40}, 0x1) /home/liam/go/pkg/mod/golang.org/[email protected]/src/database/sql/sql.go:1415 +0x71e fp=0xc0097bbb30 sp=0xc0097bb9a8 pc=0x500e5e database/sql.(*DB).query(0xc0001a5380, {0x8a6770, 0xb8cf40}, {0xc09d182000, 0x6586d}, {0x0, 0x0, 0x0}, 0x50?) /home/liam/go/pkg/mod/golang.org/[email protected]/src/database/sql/sql.go:1749 +0x57 fp=0xc0097bbba8 sp=0xc0097bbb30 pc=0x502db7 database/sql.(*DB).QueryContext.func1(0x7b?) /home/liam/go/pkg/mod/golang.org/[email protected]/src/database/sql/sql.go:1732 +0x4f fp=0xc0097bbc10 sp=0xc0097bbba8 pc=0x502cef database/sql.(*DB).retry(0xb8e3c0?, 0xc0097bbc80) /home/liam/go/pkg/mod/golang.org/[email protected]/src/database/sql/sql.go:1566 +0x42 fp=0xc0097bbc58 sp=0xc0097bbc10 pc=0x501c42 database/sql.(*DB).QueryContext(0x66000?, {0x8a6770?, 0xb8cf40?}, {0xc09d182000?, 0xc0097bbd30?}, {0x0?, 0xac25c0?, 0xc0097bbd98?}) /home/liam/go/pkg/mod/golang.org/[email protected]/src/database/sql/sql.go:1731 +0xc5 fp=0xc0097bbce8 sp=0xc0097bbc58 pc=0x502c05 database/sql.(*DB).Query(...) /home/liam/go/pkg/mod/golang.org/[email protected]/src/database/sql/sql.go:1745 github.com/jmoiron/sqlx.(*DB).Queryx(0xc000256510, {0xc09d182000?, 0x4da45a?}, {0x0?, 0xc084b72000?, 0x6586d?}) /home/liam/go/pkg/mod/github.com/jmoiron/[email protected]/sqlx.go:352 +0x4c fp=0xc0097bbd50 sp=0xc0097bbce8 pc=0x5250ec github.com/jmoiron/sqlx.Select({0x8a5d90?, 0xc000256510?}, {0x773cc0, 0xc060bdc348}, {0xc09d182000?, 0x66000000000001f4?}, {0x0?, 0x1b?, 0xc03577a600?}) /home/liam/go/pkg/mod/github.com/jmoiron/[email protected]/sqlx.go:677 +0x66 fp=0xc0097bbdc0 sp=0xc0097bbd50 pc=0x525866 github.com/jmoiron/sqlx.(*DB).Select(...) /home/liam/go/pkg/mod/github.com/jmoiron/[email protected]/sqlx.go:320I've been using the same version of this package with the same version of Go for weeks without issue. So unfortunately getting some concrete steps to reproduce it is quite difficult... I don't expect that this is enough to really solve it, but if anyone could point me in the right direction regarding my configuration below, that would be very appreciated.
There are three existing issues that refer to "segmentation fault":
- random errors when doing the db.query using Denodo odbc driver #190 - this one has a different address and is not a null pointer dereference
- fatal error: unexpected signal during runtime execution #138 - this is in _Cfunc_SQLDriverConnectW, but I'm not sure if it's the same. There wasn't a whole lot of info there.
- [db.Query error: SQLDriverConnect: {H} [unixODBC][{0} [unixODBC] #139 - this actually might be the same, but it seems like in this person's case, it happened every time that call was made. I am only experiencing this very rarely.
go version go1.22.6 linux/amd64Contents of /etc/odbcinst.ini:
[ODBC Drivers] IBM INFORMIX ODBC DRIVER=Installed [IBM INFORMIX ODBC DRIVER] Driver=/opt/informix-csdk/lib/cli/iclis09b.so Setup=/opt/informix-csdk/lib/cli/iclis09b.so APILevel=1 ConnectFunctions=YYY DriverODBCVer=03.51 FileUsage=0 SQLLevel=1And /etc/odbc.ini:
[my_server] DRIVER=/opt/informix-csdk/lib/cli/iclis09b.so DESCRIPTION=Informix DATABASE=sysmaster LOGONID=some_user pwd=some_password SERVER=some_server TRANSLATIONDLL=/opt/informix-csdk/lib/esql/igo4a304.so DB_LOCALE=en_us.819 ; ; UNICODE connection Section ; [ODBC] ;uncomment the below line for UNICODE connection UNICODE=UCS-2 ; ; Trace file Section ; TRACE=1 TRACEFILE=/tmp/odbctrace.out INSTALLDIR=/opt/informix-csdk TRACEDLL=idmrs09a.soI have tracing enabled. Here is what I believe is the relevant entry:
ppid=002aa62d,pid=00000000 ENTER 2024-10-28 19:26:41 SQLDriverConnectW SQLHDBC 0x7FAEFC011830 SQLHWND 0000 SQLWCHAR ***** SQLSMALLINT -3 SQLWCHAR * (null) SQLSMALLINT 0 SQLSMALLINT * 0x7FAF59B526C0 SQLUSMALLINT 0Thank you again for such a great library, and for your time.
Source code, the table schema and data (for testing),may help.