diff mbox series

[1/5] libsepol: free memory on str_read() failures

Message ID 20230713180816.101924-1-cgzones@googlemail.com (mailing list archive)
State Not Applicable
Delegated to: Petr Lautrbach
Headers show
Series [1/5] libsepol: free memory on str_read() failures | expand

Commit Message

Christian Göttsche July 13, 2023, 6:08 p.m. UTC
If str_read() fails to read the next entry it has already allocated
memory for it.
Free the passed pointer also in the error case.

Reported-by: oss-fuzz (issue 60567)
Signed-off-by: Christian Göttsche <cgzones@googlemail.com>
---
 libsepol/src/avtab.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/libsepol/src/avtab.c b/libsepol/src/avtab.c
index 99fdaa87..5c76fe12 100644
--- a/libsepol/src/avtab.c
+++ b/libsepol/src/avtab.c
@@ -857,7 +857,7 @@  static int filename_trans_read_one(avtab_t *a, void *fp)
 	len = le32_to_cpu(*buf);
 	rc = str_read(&name, fp, len);
 	if (rc < 0)
-		return SEPOL_ERR;
+		goto err;
 
 	/* read stype, ttype, tclass and otype */
 	rc = next_entry(buf, fp, sizeof(uint32_t) * 4);
@@ -898,7 +898,7 @@  static int filename_trans_comp_read_one(avtab_t *a, void *fp)
 	len = le32_to_cpu(*buf);
 	rc = str_read(&name, fp, len);
 	if (rc < 0)
-		return SEPOL_ERR;
+		goto err;
 
 	/* read ttype, tclass, ndatum */
 	rc = next_entry(buf, fp, sizeof(uint32_t) * 3);