Skip to contentSkip to conversation

libselinux: Close leaked FILEs

PATCH In review Petr Lautrbach 2 participants 3 messages Mar 11, 2022 – Mar 25, 2022 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libselinux: Close leaked FILEs

Fixes:
label_media.c:94:24: warning: leak of FILE ‘fopen (path_28, "re")’ [CWE-775] [-Wanalyzer-file-leak] label_x.c:121:24: warning: leak of FILE ‘fopen (path_28, "re")’ [CWE-775] [-Wanalyzer-file-leak]

---
 libselinux/src/label_media.c | 4 ++--
 libselinux/src/label_x.c     | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
libselinux/src/label_media.c +2 -2
index eb27deaf510e..3137c18edc19 100644
@@ -95,10 +95,10 @@ static int init(struct selabel_handle *rec, const struct selinux_opt *opts,
 	__fsetlocking(fp, FSETLOCKING_BYCALLER);
 
 	if (fstat(fileno(fp), &sb) < 0)
-		return -1;
+		goto finish;
 	if (!S_ISREG(sb.st_mode)) {
 		errno = EINVAL;
-		return -1;
+		goto finish;
 	}
 	rec->spec_file = strdup(path);
 
libselinux/src/label_x.c +2 -2
index e9fa063fafff..e6e8d9f60bff 100644
@@ -122,10 +122,10 @@ static int init(struct selabel_handle *rec, const struct selinux_opt *opts,
 	__fsetlocking(fp, FSETLOCKING_BYCALLER);
 
 	if (fstat(fileno(fp), &sb) < 0)
-		return -1;
+		goto finish;
 	if (!S_ISREG(sb.st_mode)) {
 		errno = EINVAL;
-		return -1;
+		goto finish;
 	}
 	rec->spec_file = strdup(path);
 
Signature · 1 line
2.35.1
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Petr Lautrbach

Fixes:
label_media.c:94:24: warning: leak of FILE ‘fopen (path_28, "re")’ [CWE-775] [-Wanalyzer-file-leak] label_x.c:121:24: warning: leak of FILE ‘fopen (path_28, "re")’ [CWE-775] [-Wanalyzer-file-leak]

Quoted 42 lines
---
 libselinux/src/label_media.c | 4 ++--
 libselinux/src/label_x.c     | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
libselinux/src/label_media.c +2 -2
index eb27deaf510e..3137c18edc19 100644
@@ -95,10 +95,10 @@ static int init(struct selabel_handle *rec, const struct selinux_opt *opts,
        __fsetlocking(fp, FSETLOCKING_BYCALLER);
 
        if (fstat(fileno(fp), &sb) < 0)
-               return -1;
+               goto finish;
        if (!S_ISREG(sb.st_mode)) {
                errno = EINVAL;
-               return -1;
+               goto finish;
        }
        rec->spec_file = strdup(path);
 
libselinux/src/label_x.c +2 -3
index e9fa063fafff..e6e8d9f60bff 100644
@@ -122,10 +122,10 @@ static int init(struct selabel_handle *rec, const struct selinux_opt *opts,
        __fsetlocking(fp, FSETLOCKING_BYCALLER);
 
        if (fstat(fileno(fp), &sb) < 0)
-               return -1;
+               goto finish;
        if (!S_ISREG(sb.st_mode)) {
                errno = EINVAL;
-               return -1;
+               goto finish;
        }
        rec->spec_file = strdup(path);
 
--

2.35.1

#2 lore raw
Quoted 11 lines · James Carter
Quoted 6 lines · Petr Lautrbach

Fixes:
label_media.c:94:24: warning: leak of FILE ‘fopen (path_28, "re")’ [CWE-775] [-Wanalyzer-file-leak] label_x.c:121:24: warning: leak of FILE ‘fopen (path_28, "re")’ [CWE-775] [-Wanalyzer-file-leak]

Merged.
Thanks,
Jim

Quoted 42 lines
Quoted 42 lines
---
 libselinux/src/label_media.c | 4 ++--
 libselinux/src/label_x.c     | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)
libselinux/src/label_media.c +2 -2
index eb27deaf510e..3137c18edc19 100644
@@ -95,10 +95,10 @@ static int init(struct selabel_handle *rec, const struct selinux_opt *opts,
        __fsetlocking(fp, FSETLOCKING_BYCALLER);
 
        if (fstat(fileno(fp), &sb) < 0)
-               return -1;
+               goto finish;
        if (!S_ISREG(sb.st_mode)) {
                errno = EINVAL;
-               return -1;
+               goto finish;
        }
        rec->spec_file = strdup(path);
 
libselinux/src/label_x.c +2 -3
index e9fa063fafff..e6e8d9f60bff 100644
@@ -122,10 +122,10 @@ static int init(struct selabel_handle *rec, const struct selinux_opt *opts,
        __fsetlocking(fp, FSETLOCKING_BYCALLER);
 
        if (fstat(fileno(fp), &sb) < 0)
-               return -1;
+               goto finish;
        if (!S_ISREG(sb.st_mode)) {
                errno = EINVAL;
-               return -1;
+               goto finish;
        }
        rec->spec_file = strdup(path);
 
--

2.35.1