Skip to contentSkip to conversation

module_to_cil: fix possible use of initialized value

PATCH Superseded [email protected] 1 participant 2 messages Aug 3, 2016 SELinux security module

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 module_to_cil: fix possible use of initialized value

From: William Roberts <[email protected]>

Correct errors like these reported by gcc:

module_to_cil.c: In function ‘block_to_cil’:
module_to_cil.c:229:20: error: ‘attr_list’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
struct list_node *curr = (*attr_list)->head;

Usages of attr_list_destroy() were called when list_init() fails. Just bail early on failure.

stack_init() and stack_destroy() also suffered from the aforementioned issue.

---
 libsepol/src/module_to_cil.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
libsepol/src/module_to_cil.c +4 -4
index b9a4af7..9d0d064 100644
@@ -1307,7 +1307,7 @@ static int cond_list_to_cil(int indent, struct policydb *pdb, struct cond_node *
 
 	rc = list_init(&attr_list);
 	if (rc != 0) {
-		goto exit;
+		return rc;
 	}
 
 	for (cond = cond_list; cond != NULL; cond = cond->next) {
@@ -3488,7 +3488,7 @@ static int block_to_cil(struct policydb *pdb, struct avrule_block *block, struct
 
 	rc = list_init(&attr_list);
 	if (rc != 0) {
-		goto exit;
+		return rc;
 	}
 
 	rc = typealiases_to_cil(indent, pdb, block, stack);
@@ -3635,7 +3635,7 @@ static int blocks_to_cil(struct policydb *pdb)
 
 	rc = stack_init(&stack);
 	if (rc != 0) {
-		goto exit;
+		return rc;
 	}
 
 	block = pdb->global;
@@ -3703,7 +3703,7 @@ static int linked_blocks_to_cil(struct policydb *pdb)
 
 	rc = stack_init(&stack);
 	if (rc != 0) {
-		goto exit;
+		return rc;
 	}
 
 	block = pdb->global;
Signature · 1 line
1.9.1
#1 lore raw
Quoted 8 lines

-----Original Message-----
From: Roberts, William C
Sent: Wednesday, August 3, 2016 2:37 PM
To: [email protected]; [email protected]; [email protected]
Cc: Roberts, William C <[email protected]>
Subject: [PATCH] module_to_cil: fix possible use of initialized value

Let's try this commit message again... unitialized!

Quoted 64 lines

From: William Roberts <[email protected]>

Correct errors like these reported by gcc:

module_to_cil.c: In function ‘block_to_cil’:
module_to_cil.c:229:20: error: ‘attr_list’ may be used uninitialized in this function [-Werror=maybe-uninitialized]
struct list_node *curr = (*attr_list)->head;

Usages of attr_list_destroy() were called when list_init() fails. Just bail early on failure.

stack_init() and stack_destroy() also suffered from the aforementioned issue.

---
 libsepol/src/module_to_cil.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
libsepol/src/module_to_cil.c index renamed from libsepol/src/module_to_cil.c +0 -0

b9a4af7..9d0d064 100644

libsepol/src/module_to_cil.c +1 -1
@@ -1307,7 +1307,7 @@ static int cond_list_to_cil(int indent, struct policydb
 *pdb, struct cond_node *
 
 	rc = list_init(&attr_list);
 	if (rc != 0) {
-		goto exit;
+		return rc;
 	}
 

for (cond = cond_list; cond != NULL; cond = cond->next) { @@ -3488,7
+3488,7 @@ static int block_to_cil(struct policydb *pdb, struct avrule_block *block, struct

libsepol/src/module_to_cil.c +1 -1
 	rc = list_init(&attr_list);
 	if (rc != 0) {
-		goto exit;
+		return rc;
 	}
 
 	rc = typealiases_to_cil(indent, pdb, block, stack); @@ -3635,7 +3635,7

@@ static int blocks_to_cil(struct policydb *pdb)

libsepol/src/module_to_cil.c +2 -3
 	rc = stack_init(&stack);
 	if (rc != 0) {
-		goto exit;
+		return rc;
 	}
 
 	block = pdb->global;
@@ -3703,7 +3703,7 @@ static int linked_blocks_to_cil(struct policydb *pdb)
 
 	rc = stack_init(&stack);
 	if (rc != 0) {
-		goto exit;
+		return rc;
 	}
 
 	block = pdb->global;
--

1.9.1