Fix: lttng: sanity check of `--probe` description
authorFrancis Deslauriers <francis.deslauriers@efficios.com>
Fri, 17 Jan 2020 20:09:21 +0000 (15:09 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 30 Jan 2020 21:01:20 +0000 (16:01 -0500)
Issue
=====
Run the following command:
  lttng enable-event -k --probe "\do_fork" my_do_fork_event
currently fails and that is expected.

But it does not fail for the right reason. In the `parse_probe_opts()`
function, during the last step of parsing the probe description we assume
it's a raw address and pass the string directly to the `strtoul()`
function. So if the probe description is not an address at all (e.g.
"\do_fork"), the `strtoul()` call will return 0 in the `addr` field of
the probe struct. This is then passed to the kernel tracer that asks the
kernel to instrument that address with a kprobe. This fails because 0x0
is not an address that can be instrumented.

Solution
========
Check that the first character of the tentative address is a digit
before trying to convert the string to an integer. This is not perfect
but at least it prevents some errors.

Signed-off-by: Francis Deslauriers <francis.deslauriers@efficios.com>
Change-Id: I444f0e7694098b1cdb56ecbf5d92be8974e406dc
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
src/bin/lttng/commands/enable_events.c

index 84bcb20814233c8928a53b9fd8e1d93e88b453d5..f6bae4874266863e3de6c20350565ad1dc4e0523 100644 (file)
@@ -160,8 +160,13 @@ static int parse_probe_opts(struct lttng_event *ev, char *opt)
        /* Check for address */
        match = sscanf(opt, "%" S_HEX_LEN_SCANF_IS_A_BROKEN_API "s", s_hex);
        if (match > 0) {
        /* Check for address */
        match = sscanf(opt, "%" S_HEX_LEN_SCANF_IS_A_BROKEN_API "s", s_hex);
        if (match > 0) {
-               if (*s_hex == '\0') {
-                       ERR("Invalid probe address %s", s_hex);
+               /*
+                * Return an error if the first character of the tentative
+                * address is NULL or not a digit. It can be "0" if the address
+                * is in hexadecimal and can be 1 to 9 if it's in decimal.
+                */
+               if (*s_hex == '\0' || !isdigit(*s_hex)) {
+                       ERR("Invalid probe description %s", s_hex);
                        ret = CMD_ERROR;
                        goto end;
                }
                        ret = CMD_ERROR;
                        goto end;
                }
This page took 0.025729 seconds and 4 git commands to generate.