Skip to contentSkip to conversation

libsemanage: fix use-after-free in parse_module_store()

PATCH Applied HuaxinLu 3 participants 3 messages Jun 14, 2021 – Jun 18, 2021 SELinux security module

lore
Share & tools
lore

HuaxinLu

author
#0 lore raw

PATCH 1/1 libsemanage: fix use-after-free in parse_module_store()

The passing parameter "arg" of parse_module_store will be freed after calling. A copy of parameter should be used instead of itself.

---
 libsemanage/src/conf-parse.y | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
libsemanage/src/conf-parse.y +2 -2
index 9bf9364a..eac91344 100644
@@ -516,12 +516,12 @@ static int parse_module_store(char *arg)
 		char *s;
 		current_conf->store_type = SEMANAGE_CON_POLSERV_REMOTE;
 		if ((s = strchr(arg, ':')) == NULL) {
-			current_conf->store_path = arg;
+			current_conf->store_path = strdup(arg);
 			current_conf->server_port = 4242;
 		} else {
 			char *endptr;
 			*s = '\0';
-			current_conf->store_path = arg;
+			current_conf->store_path = strdup(arg);
 			current_conf->server_port = strtol(s + 1, &endptr, 10);
 			if (*(s + 1) == '\0' || *endptr != '\0') {
 				return -2;
Signature · 1 line
2.26.0
Acked-by on v1 1/1
#1 lore raw
Quoted 5 lines · HuaxinLu

The passing parameter "arg" of parse_module_store will be freed after calling. A copy of parameter should be used instead of itself.

Quoted 26 lines
---
 libsemanage/src/conf-parse.y | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
libsemanage/src/conf-parse.y +2 -3
index 9bf9364a..eac91344 100644
@@ -516,12 +516,12 @@ static int parse_module_store(char *arg)
                char *s;
                current_conf->store_type = SEMANAGE_CON_POLSERV_REMOTE;
                if ((s = strchr(arg, ':')) == NULL) {
-                       current_conf->store_path = arg;
+                       current_conf->store_path = strdup(arg);
                        current_conf->server_port = 4242;
                } else {
                        char *endptr;
                        *s = '\0';
-                       current_conf->store_path = arg;
+                       current_conf->store_path = strdup(arg);
                        current_conf->server_port = strtol(s + 1, &endptr, 10);
                        if (*(s + 1) == '\0' || *endptr != '\0') {
                                return -2;
--

2.26.0

#2 lore raw
Quoted 8 lines · EJames Carter
Quoted 5 lines · HuaxinLu

The passing parameter "arg" of parse_module_store will be freed after calling. A copy of parameter should be used instead of itself.

Merged, thanks!

Quoted 26 lines
Quoted 26 lines
---
 libsemanage/src/conf-parse.y | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
libsemanage/src/conf-parse.y +2 -3
index 9bf9364a..eac91344 100644
@@ -516,12 +516,12 @@ static int parse_module_store(char *arg)
                char *s;
                current_conf->store_type = SEMANAGE_CON_POLSERV_REMOTE;
                if ((s = strchr(arg, ':')) == NULL) {
-                       current_conf->store_path = arg;
+                       current_conf->store_path = strdup(arg);
                        current_conf->server_port = 4242;
                } else {
                        char *endptr;
                        *s = '\0';
-                       current_conf->store_path = arg;
+                       current_conf->store_path = strdup(arg);
                        current_conf->server_port = strtol(s + 1, &endptr, 10);
                        if (*(s + 1) == '\0' || *endptr != '\0') {
                                return -2;
--

2.26.0