e836d5
From 1e84cb90b63bce841376140a7a80107e5ec1e1a8 Mon Sep 17 00:00:00 2001
e836d5
From: Adrian Reber <areber@redhat.com>
e836d5
Date: Fri, 3 May 2019 06:27:51 +0000
e836d5
Subject: [PATCH] lsm: fix compiler error 'unused-result'
e836d5
e836d5
Reading out the xattr 'security.selinux' of checkpointed sockets with
e836d5
fscanf() works (at least in theory) without checking the result of
e836d5
fscanf(). There are, however, multiple CI failures when ignoring the
e836d5
return value of fscanf().
e836d5
e836d5
This adds ferror() to check if the stream has an actual error or if '-1'
e836d5
just mean EOF.
e836d5
e836d5
Handle all errors of fscanf() // Andrei
e836d5
e836d5
Signed-off-by: Adrian Reber <areber@redhat.com>
e836d5
Signed-off-by: Andrei Vagin <avagin@gmail.com>
e836d5
---
e836d5
 criu/lsm.c | 22 +++++++++++++---------
e836d5
 1 file changed, 13 insertions(+), 9 deletions(-)
e836d5
e836d5
diff --git a/criu/lsm.c b/criu/lsm.c
e836d5
index ef6ba112b3..9c9ac7f80e 100644
e836d5
--- a/criu/lsm.c
e836d5
+++ b/criu/lsm.c
e836d5
@@ -33,8 +33,8 @@ static int apparmor_get_label(pid_t pid, char **profile_name)
e836d5
 		return -1;
e836d5
 
e836d5
 	if (fscanf(f, "%ms", profile_name) != 1) {
e836d5
-		fclose(f);
e836d5
 		pr_perror("err scanfing");
e836d5
+		fclose(f);
e836d5
 		return -1;
e836d5
 	}
e836d5
 
e836d5
@@ -111,19 +111,23 @@ static int selinux_get_label(pid_t pid, char **output)
e836d5
 static int selinux_get_sockcreate_label(pid_t pid, char **output)
e836d5
 {
e836d5
 	FILE *f;
e836d5
+	int ret;
e836d5
 
e836d5
 	f = fopen_proc(pid, "attr/sockcreate");
e836d5
 	if (!f)
e836d5
 		return -1;
e836d5
 
e836d5
-	fscanf(f, "%ms", output);
e836d5
-	/*
e836d5
-	 * No need to check the result of fscanf(). If there is something
e836d5
-	 * in /proc/PID/attr/sockcreate it will be copied to *output. If
e836d5
-	 * there is nothing it will stay NULL. So whatever fscanf() does
e836d5
-	 * it should be correct.
e836d5
-	 */
e836d5
-
e836d5
+	ret = fscanf(f, "%ms", output);
e836d5
+	if (ret == -1 && errno != 0) {
e836d5
+		pr_perror("Unable to parse /proc/%d/attr/sockcreate", pid);
e836d5
+		/*
e836d5
+		 * Only if the error indicator is set it is a real error.
e836d5
+		 * -1 could also be EOF, which would mean that sockcreate
e836d5
+		 * was just empty, which is the most common case.
e836d5
+		 */
e836d5
+		fclose(f);
e836d5
+		return -1;
e836d5
+	}
e836d5
 	fclose(f);
e836d5
 	return 0;
e836d5
 }