Skip to contentSkip to conversation

libsemanage: fix OOB cleanup in semanage_direct_list()

PATCH In review Stephen Smalley 2 participants 3 messages Jun 4 – Jun 5 SELinux security module

lore
Share & tools
lore

Stephen Smalley

author maintainer
#0 lore raw

PATCH 1/1 libsemanage: fix OOB cleanup in semanage_direct_list()

On the error path semanage_direct_list() indexes modinfo rather than (*modinfo), thereby reading and writing the wrong pointers.

---
 libsemanage/src/direct_api.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
libsemanage/src/direct_api.c +3 -4
index 6426ab14..9572dbf0 100644
@@ -2006,12 +2006,11 @@ static int semanage_direct_list(semanage_handle_t *sh,
 
 cleanup:
 	if (retval < 0) {
-		for (i = 0; i < *num_modules; i++) {
-			semanage_module_info_destroy(sh, &(*modinfo[i]));
-			modinfo[i] = NULL;
-		}
+		for (i = 0; i < *num_modules; i++)
+			semanage_module_info_destroy(sh, &(*modinfo)[i]);
 		free(*modinfo);
 		*modinfo = NULL;
+		*num_modules = 0;
 	}
 
 	if (!sh->is_in_transaction) {
Signature · 1 line
2.54.0
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · Stephen Smalley

On the error path semanage_direct_list() indexes modinfo rather than (*modinfo), thereby reading and writing the wrong pointers.

Quoted 27 lines
---
 libsemanage/src/direct_api.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
libsemanage/src/direct_api.c +3 -5
index 6426ab14..9572dbf0 100644
@@ -2006,12 +2006,11 @@ static int semanage_direct_list(semanage_handle_t *sh,
 
 cleanup:
        if (retval < 0) {
-               for (i = 0; i < *num_modules; i++) {
-                       semanage_module_info_destroy(sh, &(*modinfo[i]));
-                       modinfo[i] = NULL;
-               }
+               for (i = 0; i < *num_modules; i++)
+                       semanage_module_info_destroy(sh, &(*modinfo)[i]);
                free(*modinfo);
                *modinfo = NULL;
+               *num_modules = 0;
        }
 
        if (!sh->is_in_transaction) {
--

2.54.0

author maintainer
#2 lore raw
Quoted 10 lines · James Carter
Quoted 5 lines · Stephen Smalley

On the error path semanage_direct_list() indexes modinfo rather than (*modinfo), thereby reading and writing the wrong pointers.

Merged.

Quoted 28 lines
Quoted 28 lines
---
 libsemanage/src/direct_api.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
libsemanage/src/direct_api.c +3 -5
index 6426ab14..9572dbf0 100644
@@ -2006,12 +2006,11 @@ static int semanage_direct_list(semanage_handle_t *sh,
 
 cleanup:
        if (retval < 0) {
-               for (i = 0; i < *num_modules; i++) {
-                       semanage_module_info_destroy(sh, &(*modinfo[i]));
-                       modinfo[i] = NULL;
-               }
+               for (i = 0; i < *num_modules; i++)
+                       semanage_module_info_destroy(sh, &(*modinfo)[i]);
                free(*modinfo);
                *modinfo = NULL;
+               *num_modules = 0;
        }
 
        if (!sh->is_in_transaction) {
--

2.54.0