[lxc-devel] [PATCH 3/6] coverity: Check fstat return value

Stéphane Graber stgraber at ubuntu.com
Fri Feb 14 21:33:06 UTC 2014


Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
 src/lxc/lxc_user_nic.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/lxc/lxc_user_nic.c b/src/lxc/lxc_user_nic.c
index 60176b1..a2f0c96 100644
--- a/src/lxc/lxc_user_nic.c
+++ b/src/lxc/lxc_user_nic.c
@@ -306,7 +306,10 @@ static bool cull_entries(int fd, char *me, char *t, char *br)
 
 	nic = alloca(100);
 
-	fstat(fd, &sb);
+	if (fstat(fd, &sb) < 0) {
+		fprintf(stderr, "Failed to fstat: %s", strerror(errno));
+		return false;
+	}
 	len = sb.st_size;
 	if (len == 0)
 		return true;
@@ -383,7 +386,10 @@ static bool get_nic_if_avail(int fd, char *me, int pid, char *intype, char *br,
 	if (allowed == 0)
 		return false;
 
-	fstat(fd, &sb);
+	if (fstat(fd, &sb) < 0) {
+		fprintf(stderr, "Failed to fstat: %s", strerror(errno));
+		return false;
+	}
 	len = sb.st_size;
 	if (len != 0) {
 		buf = mmap(NULL, len, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
-- 
1.9.rc1



More information about the lxc-devel mailing list