Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OCI_SubscriptionRegister() generates a segfault on failure #323

Closed
unficyp opened this issue Feb 6, 2023 · 7 comments
Closed

OCI_SubscriptionRegister() generates a segfault on failure #323

unficyp opened this issue Feb 6, 2023 · 7 comments
Assignees

Comments

@unficyp
Copy link

unficyp commented Feb 6, 2023

Hi,
looks like #3 is back ?
using 4.7.4 on Manjaro Linux, test program connects against an 19.18 EE, oracle client:
instantclient 19.6

gdb backtrace:
`(gdb) r
Starting program: /media/gweber/Data1/develop/cpp/playground/oci_subscription_test/bin/Debug/oci_subscription_test

This GDB supports auto-downloading debuginfo from the following URLs:
https://debuginfod.archlinux.org
Enable debuginfod for this session? (y or [n]) y
Debuginfod has been enabled.
To make this setting permanent, add 'set debuginfod enabled on' to .gdbinit.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/usr/lib/libthread_db.so.1".
[New Thread 0x7ffff29ff680 (LWP 15881)]
[New Thread 0x7fffea3ff6c0 (LWP 15882)]
free(): double free detected in tcache 2

Thread 1 "oci_subscriptio" received signal SIGABRT, Aborted.
0x00007ffff79b964c in ?? () from /usr/lib/libc.so.6
(gdb) bt full
#0 0x00007ffff79b964c in ?? () from /usr/lib/libc.so.6
No symbol table info available.
#1 0x00007ffff7969938 in raise () from /usr/lib/libc.so.6
No symbol table info available.
#2 0x00007ffff795353d in abort () from /usr/lib/libc.so.6
No symbol table info available.
#3 0x00007ffff79ad7ee in ?? () from /usr/lib/libc.so.6
No symbol table info available.
#4 0x00007ffff79c33dc in ?? () from /usr/lib/libc.so.6
No symbol table info available.
#5 0x00007ffff79c5737 in ?? () from /usr/lib/libc.so.6
No symbol table info available.
#6 0x00007ffff79c7ba3 in free () from /usr/lib/libc.so.6
No symbol table info available.
#7 0x00007ffff7f71e71 in OcilibMemoryFree (ptr_mem=) at memory.c:184
block =
#8 0x00007ffff7f9933c in OcilibSubscriptionRegister (con=, name=, type=7, handler=, port=, timeout=)
at subscription.c:330
call_retval =
call_status =
call_context = {source_ptr = 0x5555556193f8, location = 0x7ffff7fa88a0 <func.6> "OcilibSubscriptionRegister", source_type = 11}
func = "OcilibSubscriptionRegister"
attr = 1
dbsize = 6
dbstr =
sub =
#9 0x000055555555c48c in ocilib::Subscription::Register (this=0x7fffffffd650, connection=..., name="sub-00", changeTypes=...,
handler=0x55555555a5a0 <EventHandler(ocilib::Event&)>, port=5468, timeout=0) at /usr/local/include/ocilibcpp/detail/Subscription.hpp:43
No locals.
#10 0x0000555555559a9d in main (argc=1, argv=0x7fffffffd978) at /media/gweber/Data1/develop/cpp/playground/oci_subscription_test/main.cpp:38
con = {<ocilib::core::HandleHolder<OCI_Connection*>> = {_smartHandle = 0x5555556692e0}, }
st = {<ocilib::core::HandleHolder<OCI_Statement*>> = {_smartHandle = 0x555555669380}, }
sub = {<ocilib::core::HandleHolder<OCI_Subscription*>> = {_smartHandle = 0x0}, }
ex = <error reading variable: Cannot access memory at address 0x0>
(gdb)
`

source is the same from https://vrogier.github.io/ocilib/doc/html/group___ocilib_cpp_api_demo_list_application.html "Database notifications" (except the instance shutdown/startup)

regards

@vrogier
Copy link
Owner

vrogier commented Feb 6, 2023

Hi,

I will have a look.
On subscription.c, line 338, if you replace FREE(sub) with sub = NULL, and then recompile ocilib, does it fix the issue ?

The issues seems to be caused by the fact OcilibSubscriptionUnregister() frees the input OCI_Subscription pointer.
In case of failure in OcilibSubscriptionRegister(), the CLEANUP_AND_EXIT_FUNC block calls OcilibSubscriptionUnregister(sub) and then calls FREE(sub) where sub is already freed.

Typcipal case of double free :( That's weird I did not see that in 4.7.4 (might be a merge issue in local branchs).

I will fixe that asap !!

Regards,

Vincent

@unficyp
Copy link
Author

unficyp commented Feb 6, 2023

hi,
thanks, yes that works, no more crashes :)

But something other caught my attention:
** Notification : sub-00 ** Database : **CDBHOME** ** Event : Object Changed .... Object : HOME.TABLE1 .... Action : Alter .... RowID :

"CDBHOME" is my container database, the PDB i'm connecting to is "HOME" - not quite sure if this is provied from oracle by design.

regards

@vrogier
Copy link
Owner

vrogier commented Feb 6, 2023

About the database name, I noticed that too recently when using pluggable databases.
in notifications, it remains the container database name. I will check if they introduced a new attribute to retrieve the PDN name.

vrogier pushed a commit that referenced this issue Feb 6, 2023
… the conditiion to automatically reproduce it)
@vrogier
Copy link
Owner

vrogier commented Feb 6, 2023

Hi,

Fix committed in v4.7.5 branch.

And about the db name issue, it seems that there is no way to retrieve the real pdb name from notifications :(

Vincent

@vrogier vrogier changed the title Crash with subscription OCI_SubscriptionRegister() generates a segfault on failure Feb 6, 2023
@vrogier vrogier closed this as completed Feb 6, 2023
@vrogier
Copy link
Owner

vrogier commented Feb 6, 2023

Hi,

v4.7.5 released.

btw, doc update to mention that OCI_EventGetDatabase() remains the container database.

Regards,

Vincent

@cjbj
Copy link

cjbj commented Feb 6, 2023

About the database name, I noticed that too recently when using pluggable databases.
in notifications, it remains the container database name.

I'll prod the CQN developers about it too.

@vrogier
Copy link
Owner

vrogier commented Feb 6, 2023

Thank you @cjbj :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants