From eb74dd9f86101cb0e979132f230474c9935bdad8 Mon Sep 17 00:00:00 2001
From: liwugang <liwugang@xiaomi.com>
Date: Thu, 15 Nov 2018 20:13:15 +0800
Subject: [PATCH] checkseapp: check the size of key value pairs

OOB write if the size of the key value pairs exceeds the max.

Test: Add a long line to the seapp_contexts file

Change-Id: Iaa3e697e7ac134eb6829b8b36b090997ca344b3a
Signed-off-by: liwugang <liwugang@xiaomi.com>
---
 tools/check_seapp.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/tools/check_seapp.c b/tools/check_seapp.c
index a7de7a2d2..fe404b1b5 100644
--- a/tools/check_seapp.c
+++ b/tools/check_seapp.c
@@ -1128,6 +1128,9 @@ static void parse_file(file_info *in_file) {
 			if (!token)
 				break;
 
+			if (token_cnt == KVP_NUM_OF_RULES)
+				goto oob;
+
 		} /*End token parsing */
 
 		rule_map *r = rule_map_new(keys, token_cnt, lineno, in_file->name, is_never_allow);
@@ -1148,6 +1151,10 @@ err:
 oom:
 	log_error("In function %s:  Out of memory\n", __FUNCTION__);
 	exit(EXIT_FAILURE);
+oob:
+	log_error("Reading file: \"%s\" line: %zu reason: the size of key pairs exceeds the MAX(%zu)\n",
+		in_file->name, lineno, KVP_NUM_OF_RULES);
+	exit(EXIT_FAILURE);
 }
 
 /**
-- 
GitLab