bt2: Add wrapper for bt_plugin_get_version
authorSimon Marchi <simon.marchi@efficios.com>
Wed, 1 May 2019 22:00:50 +0000 (18:00 -0400)
committerFrancis Deslauriers <francis.deslauriers@efficios.com>
Thu, 2 May 2019 20:50:15 +0000 (20:50 +0000)
commitfdfb7f179cc9ab67d33e83e7f59ee99df609a944
tree34b6cd4afaba98a063ff0b53ad5abf34d2178995
parent9633b20c7ba4f95bac7482262aad7c42d916da37
bt2: Add wrapper for bt_plugin_get_version

There is a subtle bug with our use of the "char **OUT" typemap for the
bt_plugin_get_version function.

THe SWIG wrapper does this:

    char *temp_value5;
    arg5 = &temp_value5;

The initial content of temp_value5 is unknown, assume that it points to
unreadable memory.  If the call to bt_plugin_get_version returns
PROPERTY_AVAILABILITY_NOT_AVAILABLE, the value of temp_value5 is
unchanged (but really, it could be anything, again we should assume it
points to unreadable memory).  However, the epilogue of the typemap will
still try to transform the C string to a Python str object.  Doing so
will cause a crash when trying to read the C string.

The fix is to make our own wrapper to bt_plugin_get_version, which
guarantees that if it returns PROPERTY_AVAILABILITY_NOT_AVAILABLE, it
will force the value of the output parameter to be NULL (which is
handled by the epilogue and transformed to None).

Setting the temporary variable to an invalid but non-zero pointer value
((void *) 1) makes this bug consistently reproducible and not rely on
random memory contents.  I suggest we keep it there, in order to quickly
find other instances of this bug in the future.

Change-Id: Idd12ca4c4d4d732b841c1e12420e46e6a5a25874
Reviewed-on: https://review.lttng.org/c/babeltrace/+/1221
Reviewed-by: Philippe Proulx <eeppeliteloop@gmail.com>
bindings/python/bt2/bt2/native_bt.i
bindings/python/bt2/bt2/native_bt_plugin.i
bindings/python/bt2/bt2/plugin.py
This page took 0.024719 seconds and 4 git commands to generate.