[lxc-devel] [lxc/master] Suppress hardcoded table sizes

Rachid-Koucha on Github lxc-bot at linuxcontainers.org
Thu Jul 11 08:02:04 UTC 2019


A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 506 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190711/c691f99f/attachment.bin>
-------------- next part --------------
From 6da7363420e5deac4ee086ec435e30441750a82c Mon Sep 17 00:00:00 2001
From: Rachid Koucha <47061324+Rachid-Koucha at users.noreply.github.com>
Date: Thu, 11 Jul 2019 10:01:36 +0200
Subject: [PATCH] Suppress hardcoded table sizes

. Use sizeof() instead of hardcoded values
. snprintf(..., size, ""...) is in error if the return code is >= size (not sufficient to set only ">")

Signed-off-by: Rachid Koucha <rachid.koucha at gmail.com>
---
 src/lxc/utils.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/lxc/utils.c b/src/lxc/utils.c
index 6d8a65818a..bf4a9c2cbd 100644
--- a/src/lxc/utils.c
+++ b/src/lxc/utils.c
@@ -1171,8 +1171,8 @@ int safe_mount(const char *src, const char *dest, const char *fstype,
 		if (srcfd < 0)
 			return srcfd;
 
-		ret = snprintf(srcbuf, 50, "/proc/self/fd/%d", srcfd);
-		if (ret < 0 || ret > 50) {
+		ret = snprintf(srcbuf, sizeof(srcbuf), "/proc/self/fd/%d", srcfd);
+		if (ret < 0 || ret >= (int)sizeof(srcbuf)) {
 			close(srcfd);
 			ERROR("Out of memory");
 			return -EINVAL;
@@ -1191,8 +1191,8 @@ int safe_mount(const char *src, const char *dest, const char *fstype,
 		return destfd;
 	}
 
-	ret = snprintf(destbuf, 50, "/proc/self/fd/%d", destfd);
-	if (ret < 0 || ret > 50) {
+	ret = snprintf(destbuf, sizeof(destbuf), "/proc/self/fd/%d", destfd);
+	if (ret < 0 || ret >= (int)sizeof(destbuf)) {
 		if (srcfd != -1)
 			close(srcfd);
 


More information about the lxc-devel mailing list