Skip to contentSkip to conversation

libselinux - get_default_type now sets EINVAL if no entry.

PATCH Applied Richard Haines 2 participants 2 messages Nov 27, 2011 – Dec 1, 2011 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libselinux - get_default_type now sets EINVAL if no entry.

get_default_type(3) now returns with errno set to EINVAL if the entry does not exist.

---
 libselinux/src/get_default_type.c |    9 +++++++--
 1 files changed, 7 insertions(+), 2 deletions(-)
libselinux/src/get_default_type.c +7 -2
index 6fd1681..ca3d291 100644
@@ -3,6 +3,7 @@
 #include <string.h>
 #include <ctype.h>
 #include "get_default_type_internal.h"
+#include <errno.h>
 
 static int find_default_type(FILE * fp, const char *role, char **type);
 
@@ -32,8 +33,10 @@ static int find_default_type(FILE * fp, const char *role, char **type)
 
 	len = strlen(role);
 	while (!feof_unlocked(fp)) {
-		if (!fgets_unlocked(buf, sizeof buf, fp))
+		if (!fgets_unlocked(buf, sizeof buf, fp)) {
+			errno = EINVAL;
 			return -1;
+		}
 		if (buf[strlen(buf) - 1])
 			buf[strlen(buf) - 1] = 0;
 
@@ -53,8 +56,10 @@ static int find_default_type(FILE * fp, const char *role, char **type)
 		}
 	}
 
-	if (!found)
+	if (!found) {
+		errno = EINVAL;
 		return -1;
+	}
 
 	t = malloc(strlen(buf) - len);
 	if (!t)
Signature · 10 lines
1.7.7.1





--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
Applied
#1 lore raw

applied to my devel branch

Quoted 50 lines · Richard Haines

get_default_type(3) now returns with errno set to EINVAL if the entry does not exist.

---
 libselinux/src/get_default_type.c |    9 +++++++--

 1 files changed, 7 insertions(+), 2 deletions(-)
libselinux/src/get_default_type.c +7 -3
index 6fd1681..ca3d291 100644
@@ -3,6 +3,7 @@
  #include <string.h>
  #include <ctype.h>
  #include "get_default_type_internal.h"
+#include <errno.h>
 
  static int find_default_type(FILE * fp, const char *role, char **type);
 
@@ -32,8 +33,10 @@ static int find_default_type(FILE * fp, const char *role, char **type)
 
        len = strlen(role);
        while (!feof_unlocked(fp)) {
-               if (!fgets_unlocked(buf, sizeof buf, fp))
+               if (!fgets_unlocked(buf, sizeof buf, fp)) {
+                       errno = EINVAL;
                        return -1;
+               }
                if (buf[strlen(buf) - 1])
                        buf[strlen(buf) - 1] = 0;
 
@@ -53,8 +56,10 @@ static int find_default_type(FILE * fp, const char *role, char **type)
                }
        }
 
-       if (!found)
+       if (!found) {
+               errno = EINVAL;
                return -1;
+       }
 
        t = malloc(strlen(buf) - len);
        if (!t)
--

1.7.7.1

Quoted 4 lines

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.

--
This message was distributed to subscribers of the selinux mailing list. If you no longer wish to subscribe, send mail to [email protected] with the words "unsubscribe selinux" without quotes as the message.