summaryrefslogtreecommitdiff
path: root/lib/igt_core.c
diff options
context:
space:
mode:
authorLucas De Marchi <lucas.demarchi@intel.com>2018-07-11 14:25:15 -0700
committerArkadiusz Hiler <arkadiusz.hiler@intel.com>2018-07-12 11:04:28 +0300
commitc963fb78ba77273fbd7d351d11a045487135c561 (patch)
treec379d90b379fcd6eda4986595efc1979be550ffd /lib/igt_core.c
parent523bc59a116c725d578a2720a1c1d117501c0ea7 (diff)
lib/igt_core: fix check for running under gdb
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. v2: remove the fix for repeating the argument on readlink() since that landed in another patch Signed-off-by: Lucas De Marchi <lucas.demarchi@intel.com> Reviewed-by: Arkadiusz Hiler <arkadiusz.hiler@intel.com>
Diffstat (limited to 'lib/igt_core.c')
-rw-r--r--lib/igt_core.c14
1 files changed, 10 insertions, 4 deletions
diff --git a/lib/igt_core.c b/lib/igt_core.c
index 2d0d78a3..3d87123c 100644
--- a/lib/igt_core.c
+++ b/lib/igt_core.c
@@ -1167,13 +1167,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 pathname[30], buf[1024];
+ ssize_t len;
sprintf(pathname, "/proc/%d/exe", getppid());
- return (readlink(pathname, buf, sizeof (buf)) != -1 &&
- strncmp(basename(buf), "gdb", 3) == 0);
+ len = readlink(pathname, buf, sizeof(buf) - 1);
+ if (len < 0)
+ return false;
+
+ buf[len] = '\0';
+
+ return strncmp(basename(buf), "gdb", 3) == 0;
}
static void __write_stderr(const char *str, size_t len)
@@ -1404,7 +1410,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);
}