[igt-dev] [PATCH i-g-t 3/4] lib/igt_core: fix check for running under gdb
Lucas De Marchi
lucas.demarchi at intel.com
Wed Jun 6 22:27:40 UTC 2018
Do not repeat the argument buf since this creates an alias for the first
one:
../lib/igt_core.c:1183:25: warning: passing argument 2 to restrict-qualified parameter aliases with argument 1 [-Wrestrict]
return (readlink (buf, buf, sizeof (buf)) != -1 &&
~~~ ^~~
Also properly check for errors and rename the function since we are checking if we are
running under gdb, not making it run under gdb. Previously we were
passing uninitialized data to basename() due to not properly adding the
nul termination.
==22293== Conditional jump or move depends on uninitialised value(s)
==22293== at 0x4C306D0: rindex (vg_replace_strmem.c:199)
==22293== by 0x4EC55DD: basename (in /usr/lib64/libc-2.27.so)
==22293== by 0x400744: running_under_gdb (in /tmp/a)
There's another problem with this function that it doesn't detect when
we are running gdb from a toolchain using a toolchain triplet, but
that's left for another patch.
Signed-off-by: Lucas De Marchi <lucas.demarchi at intel.com>
---
lib/igt_core.c | 16 +++++++++++-----
1 file changed, 11 insertions(+), 5 deletions(-)
diff --git a/lib/igt_core.c b/lib/igt_core.c
index 5092a3f0..d945375f 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -1175,13 +1175,19 @@ bool igt_can_fail(void)
return !test_with_subtests || in_fixture || in_subtest;
}
-static bool run_under_gdb(void)
+static bool running_under_gdb(void)
{
- char buf[1024];
+ char buf[1024], exe[1024];
+ ssize_t len;
sprintf(buf, "/proc/%d/exe", getppid());
- return (readlink (buf, buf, sizeof (buf)) != -1 &&
- strncmp(basename(buf), "gdb", 3) == 0);
+ len = readlink(buf, exe, sizeof(exe) - 1);
+ if (len < 0)
+ return false;
+
+ exe[len] = '\0';
+
+ return strncmp(basename(exe), "gdb", 3) == 0;
}
static void __write_stderr(const char *str, size_t len)
@@ -1412,7 +1418,7 @@ void __igt_fail_assert(const char *domain, const char *file, const int line,
print_backtrace();
- if (run_under_gdb())
+ if (running_under_gdb())
abort();
igt_fail(IGT_EXIT_FAILURE);
}
--
2.17.1
More information about the igt-dev
mailing list