Skip to contentSkip to conversation

libsepol/cil: Add check for too large of file size

PATCH Superseded James Carter 2 participants 2 messages Jun 4 SELinux security module

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libsepol/cil: Add check for too large of file size

In cil_add_file() add a check for a file size that is too large.

---
 libsepol/cil/src/cil.c | 5 +++++
 1 file changed, 5 insertions(+)
libsepol/cil/src/cil.c +5 -0
index 83377821..64d02466 100644
@@ -549,6 +549,11 @@ int cil_add_file(cil_db_t *db, const char *name, const char *data, size_t size)
 
 	cil_log(CIL_INFO, "Parsing %s\n", name);
 
+	if (size > SIZE_MAX - 2) {
+		cil_log(CIL_ERR, "File size is too large");
+		return SEPOL_ERR;
+	}
+
 	buffer = cil_malloc(size + 2);
 	memcpy(buffer, data, size);
 	memset(buffer + size, 0, 2);
Signature · 1 line
2.54.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 13 lines · James Carter

In cil_add_file() add a check for a file size that is too large.

---
 libsepol/cil/src/cil.c | 5 +++++
 1 file changed, 5 insertions(+)
libsepol/cil/src/cil.c +0 -0
index 83377821..64d02466 100644

libsepol/cil/src/cil.c int cil_add_file(cil_db_t *db, const char *name, const char *data, size_t size) · line 553

Quoted 5 lines
libsepol/cil/src/cil.c +2 -0
@@ -549,6 +549,11 @@ int cil_add_file(cil_db_t *db, const char *name, const char *data, size_t size)
 
        cil_log(CIL_INFO, "Parsing %s\n", name);
 
+       if (size > SIZE_MAX - 2) {
+               cil_log(CIL_ERR, "File size is too large");

Missing newline but otherwise

Quoted 10 lines
libsepol/cil/src/cil.c +3 -1
+               return SEPOL_ERR;
+       }
+
        buffer = cil_malloc(size + 2);
        memcpy(buffer, data, size);
        memset(buffer + size, 0, 2);
--

2.54.0