[PATCH 2/2] libselinux: selabel_digest -v: handle unexpected output

Stephen Smalley <[email protected]>
Newsgroups org.kernel.vger.selinux
Message-ID <[email protected]>
selabel_digest -v runs openssl to obtain a digest for validation but
doesn't correctly handle the case where no output is
produced. Initialize the buffer and reject unexpected output.

Signed-off-by: Stephen Smalley <[email protected]>
---
 libselinux/utils/selabel_digest.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/libselinux/utils/selabel_digest.c b/libselinux/utils/selabel_digest.c
index 2c395db6..689ca7f4 100644
--- a/libselinux/utils/selabel_digest.c
+++ b/libselinux/utils/selabel_digest.c
@@ -39,10 +39,17 @@ static int run_check_digest(const char *cmd, const char *selabel_digest,
 	}
 
 	/* Only expect one line "(stdin)= x.." so read and find first space */
+	files_digest[0] = '\0';
 	while (fgets(files_digest, sizeof(files_digest) - 1, fp) != NULL)
 		;
 
 	files_ptr = strstr(files_digest, " ");
+	if (!files_ptr) {
+		fprintf(stderr, "Unexpected output from '%s': %s\n", cmd,
+			files_digest);
+		pclose(fp);
+		return -1;
+	}
 
 	rc = strncmp(selabel_digest, files_ptr + 1, digest_len * 2);
 	if (rc) {
-- 
2.55.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.