diff mbox

[2/2] libselinux: close the subs file if fstat failed

Message ID 20170512201357.4091-2-nicolas.iooss@m4x.org (mailing list archive)
State Not Applicable
Headers show

Commit Message

Nicolas Iooss May 12, 2017, 8:13 p.m. UTC
selabel_subs_init() returned without closing cfg when a call to fstat()
failed. Fix this.

Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>
---
 libselinux/src/label.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Stephen Smalley May 15, 2017, 8:38 p.m. UTC | #1
On Fri, 2017-05-12 at 22:13 +0200, Nicolas Iooss wrote:
> selabel_subs_init() returned without closing cfg when a call to
> fstat()
> failed. Fix this.
> 
> Signed-off-by: Nicolas Iooss <nicolas.iooss@m4x.org>

Thanks, applied both patches.

> ---
>  libselinux/src/label.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/libselinux/src/label.c b/libselinux/src/label.c
> index 0e43474c352e..71a273bdeb2a 100644
> --- a/libselinux/src/label.c
> +++ b/libselinux/src/label.c
> @@ -104,7 +104,7 @@ struct selabel_sub *selabel_subs_init(const char
> *path,
>  		return list;
>  
>  	if (fstat(fileno(cfg), &sb) < 0)
> -		return list;
> +		goto out;
>  
>  	while (fgets_unlocked(buf, sizeof(buf) - 1, cfg)) {
>  		char *ptr = NULL;
diff mbox

Patch

diff --git a/libselinux/src/label.c b/libselinux/src/label.c
index 0e43474c352e..71a273bdeb2a 100644
--- a/libselinux/src/label.c
+++ b/libselinux/src/label.c
@@ -104,7 +104,7 @@  struct selabel_sub *selabel_subs_init(const char *path,
 		return list;
 
 	if (fstat(fileno(cfg), &sb) < 0)
-		return list;
+		goto out;
 
 	while (fgets_unlocked(buf, sizeof(buf) - 1, cfg)) {
 		char *ptr = NULL;