Fix: plugin-so.c: Assert failure on short name file in plugin-path
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Fri, 13 Sep 2019 21:38:12 +0000 (17:38 -0400)
committerFrancis Deslauriers <francis.deslauriers@efficios.com>
Mon, 16 Sep 2019 18:19:54 +0000 (14:19 -0400)
Issue
=====
Running the following command:
  babeltrace2 --plugin-path=./ ~/lttng-traces/ref/block_rq
in a directory containing a two(or one) characters named file, Babeltrace
aborts with this assertion failure:
  bt_plugin_so_create_all_from_file@plugin-so.c:1527  Babeltrace 2 library precondition not satisfied; error is
  bt_plugin_so_create_all_from_file@plugin-so.c:1527  Path length is too short: path-length=3, min-length=4
  bt_plugin_so_create_all_from_file@plugin-so.c:1527  Aborting...

This problem can also be triggered by placing a single character file at
the root of the file system (e.g. /a) and using the `--plugin-path=/`
parameter.
The assertion failure occurs when trying to find plugins with names that
end with `.so` and `.la` files. This `BT_ASSERT_PRE()` is erroneous
because it asserts that every file tested have one of the right file
extensions when in fact all files of the `--plugin-path` directory are
tested.

Solution
========
Remove the assertion and add an early return if we find that the file
name can not contain any of the accepted suffices.

Drawback
========
None.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: Ib98afa3735a73c2dfabcd96aace9da4c03ae41ab
Reviewed-on: https://review.lttng.org/c/babeltrace/+/2045
Reviewed-by: Simon Marchi <simon.marchi@efficios.com>
src/lib/plugin/plugin-so.c

index 260fd687e8c086df6c6d7eefacd7948e98e4bc34..01db0d0af7a279f6e85b22924b05f5b0398c53c5 100644 (file)
@@ -1522,9 +1522,19 @@ int bt_plugin_so_create_all_from_file(const char *path,
        BT_ASSERT(plugin_set_out);
        *plugin_set_out = NULL;
        path_len = strlen(path);
-       BT_ASSERT_PRE(path_len > PLUGIN_SUFFIX_LEN,
-               "Path length is too short: path-length=%zu, min-length=%zu",
-               path_len, PLUGIN_SUFFIX_LEN);
+
+       /*
+        * An SO plugin file must have a known plugin file suffix. So the file
+        * path must be longer than the suffix length.
+        */
+       if (path_len <= PLUGIN_SUFFIX_LEN) {
+               BT_LOGI("Path is too short to be an `.so` or `.la` plugin file:"
+                       "path=%s, path-length=%zu, min-length=%zu",
+                       path, path_len, PLUGIN_SUFFIX_LEN);
+               status = BT_FUNC_STATUS_NOT_FOUND;
+               goto end;
+       }
+
        BT_LOGI("Trying to create all SO plugins from file: path=\"%s\"", path);
        path_len++;
 
This page took 0.02539 seconds and 4 git commands to generate.