Skip to contentSkip to conversation

policycoreutils: strdup() check, use null character

PATCH In review Kalevi Kolttonen 2 participants 5 messages Jun 14 – Jun 15 SELinux security module

lore
Share & tools
lore
#0 lore raw

cover policycoreutils: strdup() check, use null character

policycoreutils: Use null character in strings. Check strdup() failure.

Kalevi Kolttonen (2):
policycoreutils: use null character in strings
policycoreutils: check strdup() failure

 policycoreutils/secon/secon.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
Signature · 1 line
2.54.0
#1 lore raw

PATCH 1/2 policycoreutils: use null character in strings

---
 policycoreutils/secon/secon.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
policycoreutils/secon/secon.c +2 -2
index 2f2b06ed..6d4bff94 100644
@@ -373,7 +373,7 @@ static int my_getXcon_raw(pid_t pid, char **con, const char *val)
 		char *tmp = strchr(ptr, '\n');
 
 		if (tmp)
-			*tmp = 0;
+			*tmp = '\0';
 
 		if (*ptr && !(*con = strdup(ptr)))
 			return (-1);
@@ -422,7 +422,7 @@ static char *get_scon(void)
 				    " Couldn't read security context");
 
 			ptr += strspn(ptr, " \n\t");
-			ptr[strcspn(ptr, " \n\t")] = 0;
+			ptr[strcspn(ptr, " \n\t")] = '\0';
 		}
 
 		if (!(con_tmp = strdup(ptr)))
Signature · 1 line
2.54.0
maintainer Acked-by on v1 1/2
#2 lore raw

Re: [PATCH 1/2] policycoreutils: use null character in strings

Quoted 2 lines · Kalevi Kolttonen
Quoted 30 lines
---
 policycoreutils/secon/secon.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
policycoreutils/secon/secon.c +2 -3
index 2f2b06ed..6d4bff94 100644
@@ -373,7 +373,7 @@ static int my_getXcon_raw(pid_t pid, char **con, const char *val)
                char *tmp = strchr(ptr, '\n');
 
                if (tmp)
-                       *tmp = 0;
+                       *tmp = '\0';
 
                if (*ptr && !(*con = strdup(ptr)))
                        return (-1);
@@ -422,7 +422,7 @@ static char *get_scon(void)
                                    " Couldn't read security context");
 
                        ptr += strspn(ptr, " \n\t");
-                       ptr[strcspn(ptr, " \n\t")] = 0;
+                       ptr[strcspn(ptr, " \n\t")] = '\0';
                }
 
                if (!(con_tmp = strdup(ptr)))
--

2.54.0

#3 lore raw

PATCH 2/2 policycoreutils: check strdup() failure

In reply to Kalevi Kolttonen
---
 policycoreutils/secon/secon.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
policycoreutils/secon/secon.c +4 -1
index 6d4bff94..48daf9d5 100644
@@ -516,8 +516,11 @@ static char *get_scon(void)
 			    " Couldn't get security context for pid %lu",
 			    (unsigned long)opts->f.pid);
 
-		if (!con)
+		if (!con) {
 			con = strdup(dummy_NIL);
+			if (!con)
+				err(EXIT_FAILURE, "Out of memory");
+		}
 		break;
 
 	case OPTS_FROM_FILE:
Signature · 1 line
2.54.0
maintainer Acked-by on v1 2/2
#4 lore raw

Re: [PATCH 2/2] policycoreutils: check strdup() failure

Quoted 2 lines · Kalevi Kolttonen
Quoted 25 lines
---
 policycoreutils/secon/secon.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
policycoreutils/secon/secon.c +4 -2
index 6d4bff94..48daf9d5 100644
@@ -516,8 +516,11 @@ static char *get_scon(void)
                            " Couldn't get security context for pid %lu",
                            (unsigned long)opts->f.pid);
 
-               if (!con)
+               if (!con) {
                        con = strdup(dummy_NIL);
+                       if (!con)
+                               err(EXIT_FAILURE, "Out of memory");
+               }
                break;
 
        case OPTS_FROM_FILE:
--

2.54.0