Skip to contentSkip to conversation

libsepol/tests: read_binary_policy() does not use f.handle

PATCH Applied Nicolas Iooss 2 participants 4 messages Jun 9, 2018 – Jun 15, 2018 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 libsepol/tests: read_binary_policy() does not use f.handle

f.handle is never set in read_binary_policy() so there is no need to call sepol_handle_destroy() on it. Moreover clang's static analyzer warns about an uninitialized argument value in the first call.

---
 libsepol/tests/test-downgrade.c | 2 --
 1 file changed, 2 deletions(-)
libsepol/tests/test-downgrade.c +0 -2
index 1ee7ff4c7e7f..50807c1dd6ea 100644
@@ -210,7 +210,6 @@ int read_binary_policy(const char *path, policydb_t *p)
 	if ((in_fp = fopen(path, "rb")) == NULL) {
 		fprintf(stderr, "Unable to open %s: %s\n", path,
 			strerror(errno));
-		sepol_handle_destroy(f.handle);
 		return -1;
 	}
 
@@ -220,7 +219,6 @@ int read_binary_policy(const char *path, policydb_t *p)
 	f.fp = in_fp;
 	rc = policydb_read(p, &f, 0);
 
-	sepol_handle_destroy(f.handle);
 	fclose(in_fp);
 	return rc;
 }
Signature · 1 line
2.17.1
#1 lore raw

PATCH 2/3 libsepol/tests: fix use of unitialized variable

When write_binary_policy() fails to open the binary policy, it calls sepol_handle_destroy(f.handle) but structure f has not been initialized at this point. Use variable handle instead.

This issue has been found using clang's static analyzer.

---
 libsepol/tests/test-downgrade.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/tests/test-downgrade.c +1 -1
index 50807c1dd6ea..963f3fabedc7 100644
@@ -254,7 +254,7 @@ int write_binary_policy(const char *path, policydb_t *p)
 	if ((out_fp = fopen(path, "w" )) == NULL) {
 		fprintf(stderr, "Unable to open %s: %s\n", path,
 			strerror(errno));
-		sepol_handle_destroy(f.handle);
+		sepol_handle_destroy(handle);
 		return -1;
 	}
 
Signature · 1 line
2.17.1
#2 lore raw

PATCH 3/3 libsepol/cil: use a colon instead of a semicolon to report rc

In reply to Nicolas Iooss
---
 libsepol/cil/src/cil_resolve_ast.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/cil/src/cil_resolve_ast.c +1 -1
index 02259241ddfe..fb9d91745629 100644
@@ -2923,7 +2923,7 @@ int cil_resolve_call1(struct cil_tree_node *current, void *extra_args)
 
 					rc = cil_fill_ipaddr(pc->cl_head, ipaddr);
 					if (rc != SEPOL_OK) {
-						cil_log(CIL_ERR, "Failed to create anonymous ip address, rc; %d\n", rc);
+						cil_log(CIL_ERR, "Failed to create anonymous ip address, rc: %d\n", rc);
 						cil_destroy_ipaddr(ipaddr);
 						goto exit;
 					}
Signature · 1 line
2.17.1
#3 lore raw

Re: [PATCH 3/3] libsepol/cil: use a colon instead of a semicolon to report rc

Quoted 1 line · Nicolas Iooss

Thanks, applied all three.

Quoted 18 lines
---
 libsepol/cil/src/cil_resolve_ast.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/cil/src/cil_resolve_ast.c +1 -1
index 02259241ddfe..fb9d91745629 100644
@@ -2923,7 +2923,7 @@ int cil_resolve_call1(struct cil_tree_node *current, void *extra_args)
 
 					rc = cil_fill_ipaddr(pc->cl_head, ipaddr);
 					if (rc != SEPOL_OK) {
-						cil_log(CIL_ERR, "Failed to create anonymous ip address, rc; %d\n", rc);
+						cil_log(CIL_ERR, "Failed to create anonymous ip address, rc: %d\n", rc);
 						cil_destroy_ipaddr(ipaddr);
 						goto exit;
 					}