[1/4] sysctl: append '\0' in sysctl_read_char

Submitted by Pavel Tikhomirov on June 30, 2016, 3:52 p.m.

Details

Message ID 1467301940-6728-2-git-send-email-ptikhomirov@virtuozzo.com
State Accepted
Series "c/r non-dev net syctls"
Commit dc72792ce349b638879dc8267a4324ab4cfeedac
Headers show

Commit Message

Pavel Tikhomirov June 30, 2016, 3:52 p.m.
Before these patch one need to zero-init char buffer before giving
it to sysctl_op, it can be convenient to remove these restriction.

https://jira.sw.ru/browse/PSBM-48397
Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
---
 criu/sysctl.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

Patch hide | download patch | download mbox

diff --git a/criu/sysctl.c b/criu/sysctl.c
index 77d9bda..87bd267 100644
--- a/criu/sysctl.c
+++ b/criu/sysctl.c
@@ -130,12 +130,13 @@  sysctl_read_char(int fd, struct sysctl_req *req, char *arg, int nr)
 	int ret = -1;
 
 	pr_debug("%s nr %d\n", req->name, nr);
-	ret = read(fd, arg, nr);
+	ret = read(fd, arg, nr - 1);
 	if (ret < 0) {
 		if (errno != EIO ||  !(req->flags & CTL_FLAGS_READ_EIO_SKIP))
 			pr_perror("Can't read %s", req->name);
 		goto err;
 	}
+	arg[ret]='\0';
 	ret = 0;
 
 err: