From 38a633b50f0ee369570e1eadee724f62d59553b0 Mon Sep 17 00:00:00 2001 From: Petri Latvala Date: Wed, 26 Sep 2018 16:24:20 +0300 Subject: runner: Avoid null characters in results.json CI pipeline (namely, cibuglog) doesn't cope well with strings that have \0 in them. If null characters appear in output files, pretend the output stops at the first such character. Well behaving tests should not print them anyway. The case in CI happened due to some hang/crash/explosion/solar flare that corrupted the output of a test. Signed-off-by: Petri Latvala Cc: Arkadiusz Hiler Cc: Tomi Sarvela Cc: Martin Peres Acked-by: Martin Peres Acked-by: Tomi Sarvela --- runner/resultgen.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'runner') diff --git a/runner/resultgen.c b/runner/resultgen.c index d34b52db..e8a60083 100644 --- a/runner/resultgen.c +++ b/runner/resultgen.c @@ -313,7 +313,7 @@ static bool fill_from_output(int fd, const char *binary, const char *key, struct subtests *subtests, struct json_object *tests) { - char *buf, *bufend; + char *buf, *bufend, *nullchr; struct stat statbuf; char piglit_name[256]; char *igt_version = NULL; @@ -332,6 +332,14 @@ static bool fill_from_output(int fd, const char *binary, const char *key, buf = NULL; } + /* + * Avoid null characters: Just pretend the output stops at the + * first such character, if any. + */ + if ((nullchr = memchr(buf, '\0', statbuf.st_size)) != NULL) { + statbuf.st_size = nullchr - buf; + } + bufend = buf + statbuf.st_size; igt_version = find_line_starting_with(buf, IGT_VERSIONSTRING, bufend); -- cgit v1.2.3