Message ID | 20220311115330.922386-1-plautrba@redhat.com (mailing list archive) |
---|---|
State | Accepted |
Commit | c1a8da6e4a2b |
Headers | show |
Series | libselinux: Close leaked FILEs | expand |
On Fri, Mar 11, 2022 at 5:10 PM Petr Lautrbach <plautrba@redhat.com> wrote: > > 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] > > Signed-off-by: Petr Lautrbach <plautrba@redhat.com> Acked-by: James Carter <jwcart2@gmail.com> > --- > libselinux/src/label_media.c | 4 ++-- > libselinux/src/label_x.c | 4 ++-- > 2 files changed, 4 insertions(+), 4 deletions(-) > > diff --git a/libselinux/src/label_media.c b/libselinux/src/label_media.c > index eb27deaf510e..3137c18edc19 100644 > --- a/libselinux/src/label_media.c > +++ b/libselinux/src/label_media.c > @@ -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); > > diff --git a/libselinux/src/label_x.c b/libselinux/src/label_x.c > index e9fa063fafff..e6e8d9f60bff 100644 > --- a/libselinux/src/label_x.c > +++ b/libselinux/src/label_x.c > @@ -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 >
On Mon, Mar 14, 2022 at 3:48 PM James Carter <jwcart2@gmail.com> wrote: > > On Fri, Mar 11, 2022 at 5:10 PM Petr Lautrbach <plautrba@redhat.com> wrote: > > > > 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] > > > > Signed-off-by: Petr Lautrbach <plautrba@redhat.com> > > Acked-by: James Carter <jwcart2@gmail.com> > Merged. Thanks, Jim > > --- > > libselinux/src/label_media.c | 4 ++-- > > libselinux/src/label_x.c | 4 ++-- > > 2 files changed, 4 insertions(+), 4 deletions(-) > > > > diff --git a/libselinux/src/label_media.c b/libselinux/src/label_media.c > > index eb27deaf510e..3137c18edc19 100644 > > --- a/libselinux/src/label_media.c > > +++ b/libselinux/src/label_media.c > > @@ -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); > > > > diff --git a/libselinux/src/label_x.c b/libselinux/src/label_x.c > > index e9fa063fafff..e6e8d9f60bff 100644 > > --- a/libselinux/src/label_x.c > > +++ b/libselinux/src/label_x.c > > @@ -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 > >
diff --git a/libselinux/src/label_media.c b/libselinux/src/label_media.c index eb27deaf510e..3137c18edc19 100644 --- a/libselinux/src/label_media.c +++ b/libselinux/src/label_media.c @@ -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); diff --git a/libselinux/src/label_x.c b/libselinux/src/label_x.c index e9fa063fafff..e6e8d9f60bff 100644 --- a/libselinux/src/label_x.c +++ b/libselinux/src/label_x.c @@ -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);
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] Signed-off-by: Petr Lautrbach <plautrba@redhat.com> --- libselinux/src/label_media.c | 4 ++-- libselinux/src/label_x.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-)