Skip to contentSkip to conversation

libsemanage: always check append_arg return value

PATCH In review Nicolas Iooss 2 participants 3 messages Apr 22, 2018 – Apr 25, 2018 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libsemanage: always check append_arg return value

When split_args() calls append_arg(), the returned value needs to be checked in order to detect memory allocation failure. Checks were missing in two places, which are spotted by clang's static analyzer:

    semanage_store.c:1352:7: warning: Value stored to 'rc' is never
    read
            rc = append_arg(&argv, &num_args, arg);
            ^    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    semanage_store.c:1368:3: warning: Value stored to 'rc' is never read
            rc = append_arg(&argv, &num_args, arg);
            ^    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---
 libsemanage/src/semanage_store.c | 4 ++++
 1 file changed, 4 insertions(+)
libsemanage/src/semanage_store.c +4 -0
index 14ad99c152ad..bce648c46464 100644
@@ -1350,6 +1350,8 @@ static char **split_args(const char *arg0, char *arg_string,
 				if (isspace(*s) && !in_quote && !in_dquote) {
 					if (arg != NULL) {
 						rc = append_arg(&argv, &num_args, arg);
+						if (rc)
+							goto cleanup;
 						free(arg);
 						arg = NULL;
 					}
@@ -1366,6 +1368,8 @@ static char **split_args(const char *arg0, char *arg_string,
 	}
 	if (arg != NULL) {
 		rc = append_arg(&argv, &num_args, arg);
+		if (rc)
+			goto cleanup;
 		free(arg);
 		arg = NULL;
 	}
Signature · 1 line
2.17.0
#1 lore raw
Quoted 40 lines · Nicolas Iooss

When split_args() calls append_arg(), the returned value needs to be checked in order to detect memory allocation failure. Checks were missing in two places, which are spotted by clang's static analyzer:

    semanage_store.c:1352:7: warning: Value stored to 'rc' is never
    read
            rc = append_arg(&argv, &num_args, arg);
            ^    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    semanage_store.c:1368:3: warning: Value stored to 'rc' is never read
            rc = append_arg(&argv, &num_args, arg);
            ^    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---
 libsemanage/src/semanage_store.c | 4 ++++
 1 file changed, 4 insertions(+)
libsemanage/src/semanage_store.c +4 -1
index 14ad99c152ad..bce648c46464 100644
@@ -1350,6 +1350,8 @@ static char **split_args(const char *arg0, char *arg_string,
                                if (isspace(*s) && !in_quote && !in_dquote) {
                                        if (arg != NULL) {
                                                rc = append_arg(&argv, &num_args, arg);
+                                               if (rc)
+                                                       goto cleanup;
                                                free(arg);
                                                arg = NULL;
                                        }
@@ -1366,6 +1368,8 @@ static char **split_args(const char *arg0, char *arg_string,
        }
        if (arg != NULL) {
                rc = append_arg(&argv, &num_args, arg);
+               if (rc)
+                       goto cleanup;
                free(arg);
                arg = NULL;
        }
--
Quoted 3 lines

2.17.0

ack

#2 lore raw

Merged: https://github.com/SELinuxProject/selinux/pull/94

Quoted 46 lines · William Roberts
Quoted 40 lines · Nicolas Iooss

When split_args() calls append_arg(), the returned value needs to be checked in order to detect memory allocation failure. Checks were missing in two places, which are spotted by clang's static analyzer:

    semanage_store.c:1352:7: warning: Value stored to 'rc' is never
    read
            rc = append_arg(&argv, &num_args, arg);
            ^    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    semanage_store.c:1368:3: warning: Value stored to 'rc' is never read
            rc = append_arg(&argv, &num_args, arg);
            ^    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
---
 libsemanage/src/semanage_store.c | 4 ++++
 1 file changed, 4 insertions(+)
libsemanage/src/semanage_store.c +4 -1
index 14ad99c152ad..bce648c46464 100644
@@ -1350,6 +1350,8 @@ static char **split_args(const char *arg0, char *arg_string,
                                if (isspace(*s) && !in_quote && !in_dquote) {
                                        if (arg != NULL) {
                                                rc = append_arg(&argv, &num_args, arg);
+                                               if (rc)
+                                                       goto cleanup;
                                                free(arg);
                                                arg = NULL;
                                        }
@@ -1366,6 +1368,8 @@ static char **split_args(const char *arg0, char *arg_string,
        }
        if (arg != NULL) {
                rc = append_arg(&argv, &num_args, arg);
+               if (rc)
+                       goto cleanup;
                free(arg);
                arg = NULL;
        }
--
Quoted 3 lines

2.17.0

ack