Skip to contentSkip to conversation

module_to_cil: fix possible use of initialized value

PATCH Applied [email protected] 2 participants 2 messages Aug 4, 2016 – Aug 5, 2016 SELinux security module

lore
Share & tools
lore
#0 lore raw

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

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

To correct the issue, initialize stack and list variables to NULL.

---
 libsepol/src/module_to_cil.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
libsepol/src/module_to_cil.c +5 -5
index b9a4af7..c74f357 100644
@@ -1303,11 +1303,11 @@ static int cond_list_to_cil(int indent, struct policydb *pdb, struct cond_node *
 {
 	int rc = -1;
 	struct cond_node *cond;
-	struct list *attr_list;
+	struct list *attr_list = NULL;
 
 	rc = list_init(&attr_list);
 	if (rc != 0) {
-		goto exit;
+		goto exit;;
 	}
 
 	for (cond = cond_list; cond != NULL; cond = cond->next) {
@@ -3482,7 +3482,7 @@ static int block_to_cil(struct policydb *pdb, struct avrule_block *block, struct
 {
 	int rc = -1;
 	struct avrule_decl *decl;
-	struct list *attr_list;
+	struct list *attr_list = NULL;
 
 	decl = block->branch_list;
 
@@ -3631,7 +3631,7 @@ static int blocks_to_cil(struct policydb *pdb)
 	int rc = -1;
 	struct avrule_block *block;
 	int indent = 0;
-	struct stack *stack;
+	struct stack *stack = NULL;
 
 	rc = stack_init(&stack);
 	if (rc != 0) {
@@ -3699,7 +3699,7 @@ static int linked_blocks_to_cil(struct policydb *pdb)
 	// Since it is linked, all optional blocks have been resolved
 	int rc = -1;
 	struct avrule_block *block;
-	struct stack *stack;
+	struct stack *stack = NULL;
 
 	rc = stack_init(&stack);
 	if (rc != 0) {
Signature · 1 line
1.9.1
#1 lore raw
Quoted 11 lines · On 08/04/2016 12:47 PM, [email protected] wrote:

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.

Quoted 7 lines

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

To correct the issue, initialize stack and list variables to NULL.

Applied. Thanks!

- Steve

Quoted 50 lines
---
 libsepol/src/module_to_cil.c | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)
libsepol/src/module_to_cil.c +5 -5
index b9a4af7..c74f357 100644
@@ -1303,11 +1303,11 @@ static int cond_list_to_cil(int indent, struct policydb *pdb, struct cond_node *
 {
 	int rc = -1;
 	struct cond_node *cond;
-	struct list *attr_list;
+	struct list *attr_list = NULL;
 
 	rc = list_init(&attr_list);
 	if (rc != 0) {
-		goto exit;
+		goto exit;;
 	}
 
 	for (cond = cond_list; cond != NULL; cond = cond->next) {
@@ -3482,7 +3482,7 @@ static int block_to_cil(struct policydb *pdb, struct avrule_block *block, struct
 {
 	int rc = -1;
 	struct avrule_decl *decl;
-	struct list *attr_list;
+	struct list *attr_list = NULL;
 
 	decl = block->branch_list;
 
@@ -3631,7 +3631,7 @@ static int blocks_to_cil(struct policydb *pdb)
 	int rc = -1;
 	struct avrule_block *block;
 	int indent = 0;
-	struct stack *stack;
+	struct stack *stack = NULL;
 
 	rc = stack_init(&stack);
 	if (rc != 0) {
@@ -3699,7 +3699,7 @@ static int linked_blocks_to_cil(struct policydb *pdb)
 	// Since it is linked, all optional blocks have been resolved
 	int rc = -1;
 	struct avrule_block *block;
-	struct stack *stack;
+	struct stack *stack = NULL;
 
 	rc = stack_init(&stack);
 	if (rc != 0) {