]> err.no Git - systemd/commitdiff
[PATCH] selinux patch
authorharald@redhat.com <harald@redhat.com>
Fri, 17 Dec 2004 02:59:22 +0000 (03:59 +0100)
committerGreg KH <gregkh@suse.de>
Wed, 27 Apr 2005 06:17:47 +0000 (23:17 -0700)
https://bugzilla.redhat.com/bugzilla/show_bug.cgi?id=142713

/sbin/udevstart segfaults on an ATIIXP chipset which is not supported
well by the kernel yet. There, /proc/ide/hda/media can not be read
(EIO error) and udevstart seems to give a null-pointer to an SELinux
function checking the media-type.

selinux.h

index 38c60a3588d23e56626ef54441d2d9475e8c4e97..df5bab69d70d6fcfceeabd322705e60af1bec600 100644 (file)
--- a/selinux.h
+++ b/selinux.h
@@ -30,31 +30,40 @@ static inline int selinux_get_media(char *path, int mode, char **media)
        FILE *fp;
        char buf[PATH_MAX];
        char mediabuf[PATH_MAX];
+       int ret = -1;
 
        *media = NULL;
        if (!(mode && S_IFBLK)) {
                return -1;
        }
-       snprintf(buf,sizeof(buf), "/proc/ide/%s/media", basename(path));
+
+       snprintf(buf, sizeof(buf), "/proc/ide/%s/media", basename(path));
+
        fp=fopen(buf,"r");
-       if (fp) {
-               if (fgets(mediabuf,sizeof(mediabuf), fp)) {
-                       int size = strlen(mediabuf);
-                       while (size-- > 0) {
-                               if (isspace(mediabuf[size])) {
-                                       mediabuf[size]='\0';
-                               } else {
-                                       break;
-                               }
-                       }
-                       *media = strdup(mediabuf);
-                       info("selinux_get_media(%s)->%s \n", path, *media);
+       if (!fp)
+               goto out;
+       
+       mediabuf[0] = '\0';
+
+       if (fgets(mediabuf, sizeof(mediabuf), fp) == NULL)
+               goto close_out;
+
+       int size = strlen(mediabuf);
+       while (size-- > 0) {
+               if (isspace(mediabuf[size])) {
+                       mediabuf[size]='\0';
+               } else {
+                       break;
                }
-               fclose(fp);
-               return 0;
-       } else {
-               return -1;
        }
+       *media = strdup(mediabuf);
+       info("selinux_get_media(%s)->%s \n", path, *media);
+       ret = 0;
+
+close_out:
+       fclose(fp);
+out:
+       return ret;
 }
 
 static inline void selinux_setfilecon(char *file, unsigned int mode)