From 3b02df57ef0abb02ae20ea9ef041a26280bf0c43 Mon Sep 17 00:00:00 2001 From: Tycho Andersen Date: Wed, 7 Oct 2015 15:44:00 +0300 Subject: [PATCH] util: don't chop off last element in buffer 377763e5 is incorrect since we can't always chop off the last element in the buffer: Execute static/cgroup00 ./cgroup00 --pidfile=cgroup00.pid --outfile=cgroup00.out --dirname=cgroup00.test Dump 12819 (00.003514) Error (files-reg.c:624): Can't create link remap for /dev/nul. Use link-remap option. (00.003523) Error (cr-dump.c:1257): Dump files (pid: 12819) failed with -1 (00.004042) Error (cr-dump.c:1619): Dumping FAILED. WARNING: cgroup00 returned 1 and left running for debug needs Test: zdtm/live/static/cgroup00, Result: FAIL ==================================== ERROR ==================================== Test: zdtm/live/static/cgroup00, Namespace: ================================= ERROR OVER ================================= Hopefully the >= will appease coverity (instead of just a ==). Signed-off-by: Tycho Andersen Signed-off-by: Pavel Emelyanov --- util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/util.c b/util.c index 76944486e..b4d5d5a70 100644 --- a/util.c +++ b/util.c @@ -463,11 +463,11 @@ int read_fd_link(int lfd, char *buf, size_t size) if (ret < 0) { pr_perror("Can't read link of fd %d", lfd); return -1; - } else if ((size_t)ret == size) { + } else if ((size_t)ret >= size) { pr_err("Buffer for read link of fd %d is too small\n", lfd); return -1; } - buf[ret - 1] = 0; + buf[ret] = 0; return ret; }