diff mbox series

[4/4] libsepol: Initialize "strs" on declaration

Message ID 20241022090314.173002-4-vmojzis@redhat.com (mailing list archive)
State New
Headers show
Series [1/4] libsepol/cil: Initialize avtab_datum on declaration | expand

Commit Message

Vit Mojzis Oct. 22, 2024, 9:03 a.m. UTC
The value of "strs" was not always initialized before being used by
strs_destroy.

Fixes:
Error: UNINIT (CWE-457):
libsepol-3.7/src/kernel_to_cil.c:1439:2: var_decl: Declaring variable "strs" without initializer.
libsepol-3.7/src/kernel_to_cil.c:1487:2: uninit_use_in_call: Using uninitialized value "strs" when calling "strs_destroy".
 \# 1485|
 \# 1486|   exit:
 \# 1487|-> 	strs_destroy(&strs);
 \# 1488|
 \# 1489|   	if (rc != 0) {

Error: UNINIT (CWE-457):
libsepol-3.7/src/kernel_to_conf.c:1422:2: var_decl: Declaring variable "strs" without initializer.
libsepol-3.7/src/kernel_to_conf.c:1461:2: uninit_use_in_call: Using uninitialized value "strs" when calling "strs_destroy".
 \# 1459|
 \# 1460|   exit:
 \# 1461|-> 	strs_destroy(&strs);
 \# 1462|
 \# 1463|   	if (rc != 0) {

Signed-off-by: Vit Mojzis <vmojzis@redhat.com>
---
 libsepol/src/kernel_to_cil.c  | 2 +-
 libsepol/src/kernel_to_conf.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

Comments

James Carter Oct. 22, 2024, 8:27 p.m. UTC | #1
On Tue, Oct 22, 2024 at 5:09 AM Vit Mojzis <vmojzis@redhat.com> wrote:
>
> The value of "strs" was not always initialized before being used by
> strs_destroy.
>
> Fixes:
> Error: UNINIT (CWE-457):
> libsepol-3.7/src/kernel_to_cil.c:1439:2: var_decl: Declaring variable "strs" without initializer.
> libsepol-3.7/src/kernel_to_cil.c:1487:2: uninit_use_in_call: Using uninitialized value "strs" when calling "strs_destroy".
>  \# 1485|
>  \# 1486|   exit:
>  \# 1487|->     strs_destroy(&strs);
>  \# 1488|
>  \# 1489|       if (rc != 0) {
>
> Error: UNINIT (CWE-457):
> libsepol-3.7/src/kernel_to_conf.c:1422:2: var_decl: Declaring variable "strs" without initializer.
> libsepol-3.7/src/kernel_to_conf.c:1461:2: uninit_use_in_call: Using uninitialized value "strs" when calling "strs_destroy".
>  \# 1459|
>  \# 1460|   exit:
>  \# 1461|->     strs_destroy(&strs);
>  \# 1462|
>  \# 1463|       if (rc != 0) {
>
> Signed-off-by: Vit Mojzis <vmojzis@redhat.com>

Acked-by: James Carter <jwcart2@gmail.com>

> ---
>  libsepol/src/kernel_to_cil.c  | 2 +-
>  libsepol/src/kernel_to_conf.c | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/libsepol/src/kernel_to_cil.c b/libsepol/src/kernel_to_cil.c
> index 7243b3c0..2d563e7d 100644
> --- a/libsepol/src/kernel_to_cil.c
> +++ b/libsepol/src/kernel_to_cil.c
> @@ -1436,7 +1436,7 @@ static int map_type_aliases_to_strs(char *key, void *data, void *args)
>  static int write_type_alias_rules_to_cil(FILE *out, struct policydb *pdb)
>  {
>         type_datum_t *alias;
> -       struct strs *strs;
> +       struct strs *strs = NULL;
>         char *name;
>         char *type;
>         unsigned i, num = 0;
> diff --git a/libsepol/src/kernel_to_conf.c b/libsepol/src/kernel_to_conf.c
> index ca91ffae..661546af 100644
> --- a/libsepol/src/kernel_to_conf.c
> +++ b/libsepol/src/kernel_to_conf.c
> @@ -1419,7 +1419,7 @@ static int map_type_aliases_to_strs(char *key, void *data, void *args)
>  static int write_type_alias_rules_to_conf(FILE *out, struct policydb *pdb)
>  {
>         type_datum_t *alias;
> -       struct strs *strs;
> +       struct strs *strs = NULL;
>         char *name;
>         char *type;
>         unsigned i, num = 0;
> --
> 2.47.0
>
>
diff mbox series

Patch

diff --git a/libsepol/src/kernel_to_cil.c b/libsepol/src/kernel_to_cil.c
index 7243b3c0..2d563e7d 100644
--- a/libsepol/src/kernel_to_cil.c
+++ b/libsepol/src/kernel_to_cil.c
@@ -1436,7 +1436,7 @@  static int map_type_aliases_to_strs(char *key, void *data, void *args)
 static int write_type_alias_rules_to_cil(FILE *out, struct policydb *pdb)
 {
 	type_datum_t *alias;
-	struct strs *strs;
+	struct strs *strs = NULL;
 	char *name;
 	char *type;
 	unsigned i, num = 0;
diff --git a/libsepol/src/kernel_to_conf.c b/libsepol/src/kernel_to_conf.c
index ca91ffae..661546af 100644
--- a/libsepol/src/kernel_to_conf.c
+++ b/libsepol/src/kernel_to_conf.c
@@ -1419,7 +1419,7 @@  static int map_type_aliases_to_strs(char *key, void *data, void *args)
 static int write_type_alias_rules_to_conf(FILE *out, struct policydb *pdb)
 {
 	type_datum_t *alias;
-	struct strs *strs;
+	struct strs *strs = NULL;
 	char *name;
 	char *type;
 	unsigned i, num = 0;