[CRIU] [PATCH] util: don't chop off last element in buffer

Tycho Andersen tycho.andersen at canonical.com
Wed Oct 7 05:44:07 PDT 2015


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 <tycho.andersen at canonical.com>
---
 util.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/util.c b/util.c
index 7694448..b4d5d5a 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;
 }
-- 
2.1.4



More information about the CRIU mailing list