diff options
author | Robert Foss <robert.foss@collabora.com> | 2017-01-06 09:28:50 +0000 |
---|---|---|
committer | Robert Foss <robert.foss@collabora.com> | 2017-01-20 09:30:24 -0500 |
commit | b1f931b0c3be12d52d9b15627eb1b2fb2efdd467 (patch) | |
tree | d750eeb207033c0ff486a20f9a0cd1d513ba6afb /lib/igt_debugfs.c | |
parent | ac1d818ba12f9893a7aa481a7c050e7833dbed34 (diff) |
lib/igt_debugfs: Prevent buffer overflow
buf array may overflow with when writing '\0' if
MAX_LINE_LEN bytes are read during read().
Signed-off-by: Robert Foss <robert.foss@collabora.com>
Reviewed-by: Petri Latvala <petri.latvala@intel.com>
Diffstat (limited to 'lib/igt_debugfs.c')
-rw-r--r-- | lib/igt_debugfs.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/lib/igt_debugfs.c b/lib/igt_debugfs.c index d828687a..982573d7 100644 --- a/lib/igt_debugfs.c +++ b/lib/igt_debugfs.c @@ -597,10 +597,12 @@ static int read_crc(igt_pipe_crc_t *pipe_crc, igt_crc_t *out) bytes_read = read(pipe_crc->crc_fd, &buf, read_len); igt_reset_timeout(); - if (bytes_read < 0 && errno == EAGAIN) { + if (bytes_read < 0 && errno == EAGAIN) igt_assert(pipe_crc->flags & O_NONBLOCK); + + if (bytes_read < 0) bytes_read = 0; - } + buf[bytes_read] = '\0'; if (bytes_read && !pipe_crc_init_from_string(pipe_crc, out, buf)) |