Skip to contentSkip to conversation

libsepol: free potential transition tables on insertion failure

PATCH In review Christian Göttsche 2 participants 2 messages Jul 14, 2023 – Aug 4, 2023 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libsepol: free potential transition tables on insertion failure

If the insertion via the callback insertf fails, free the potential previously allocated transition hashtables.

---
 libsepol/src/avtab.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
libsepol/src/avtab.c +6 -1
index 99fdaa87..6c74eff7 100644
@@ -715,7 +715,12 @@ int avtab_read_item(struct policy_file *fp, uint32_t vers, avtab_t * a,
 		}
 		datum.data = le32_to_cpu(*buf32);
 	}
-	return insertf(a, &key, &datum, p);
+
+	rc = insertf(a, &key, &datum, p);
+	if (rc < 0)
+		avtab_trans_destroy(&trans);
+
+	return rc;
 }
 
 static int avtab_insertf(avtab_t * a, avtab_key_t * k, avtab_datum_t * d,
Signature · 1 line
2.40.1
#1 lore raw
Quoted 28 lines · Christian Göttsche

If the insertion via the callback insertf fails, free the potential previously allocated transition hashtables.

---
 libsepol/src/avtab.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
libsepol/src/avtab.c +6 -2
index 99fdaa87..6c74eff7 100644
@@ -715,7 +715,12 @@ int avtab_read_item(struct policy_file *fp, uint32_t vers, avtab_t * a,
                }
                datum.data = le32_to_cpu(*buf32);
        }
-       return insertf(a, &key, &datum, p);
+
+       rc = insertf(a, &key, &datum, p);
+       if (rc < 0)
+               avtab_trans_destroy(&trans);
+
+       return rc;
 }
 
 static int avtab_insertf(avtab_t * a, avtab_key_t * k, avtab_datum_t * d,
--
Quoted 2 lines

2.40.1

This patch depended on the prefix/suffix patches which have been reverted. Jim