Skip to contentSkip to conversation

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

PATCH In review James Carter 2 participants 3 messages Jun 4 – Jun 5 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH v2 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.

---
v2: Add '\n' to end of log message

 libsepol/cil/src/cil.c | 5 +++++
 1 file changed, 5 insertions(+)
libsepol/cil/src/cil.c +5 -0
index 83377821..18b98fe2 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\n");
+		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 v2 1/1
#1 lore raw
Quoted 4 lines · James Carter

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

Quoted 26 lines

---
v2: Add '\n' to end of log message

 libsepol/cil/src/cil.c | 5 +++++
 1 file changed, 5 insertions(+)
libsepol/cil/src/cil.c +5 -1
index 83377821..18b98fe2 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\n");
+               return SEPOL_ERR;
+       }
+
        buffer = cil_malloc(size + 2);
        memcpy(buffer, data, size);
        memset(buffer + size, 0, 2);
--

2.54.0

#2 lore raw
Quoted 9 lines · Stephen Smalley
Quoted 4 lines · James Carter

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

Merged.
Jim

Quoted 26 lines
Quoted 26 lines

---
v2: Add '\n' to end of log message

 libsepol/cil/src/cil.c | 5 +++++
 1 file changed, 5 insertions(+)
libsepol/cil/src/cil.c +5 -1
index 83377821..18b98fe2 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\n");
+               return SEPOL_ERR;
+       }
+
        buffer = cil_malloc(size + 2);
        memcpy(buffer, data, size);
        memset(buffer + size, 0, 2);
--

2.54.0