Patchwork lib: fwts_uefi: only close fp if it was successfully opened

login
register
mail settings
Submitter Colin King
Date May 6, 2013, 11:25 p.m.
Message ID <1367882708-21822-1-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/241829/
State Accepted
Headers show

Comments

Colin King - May 6, 2013, 11:25 p.m.
From: Colin Ian King <colin.king@canonical.com>

Coverity CID #997293, Dereference after null check (FORWARD_NULL)

Coverity caught a bug where we are closing fp even if it failed
to open.  Close it only if it opens correctly and fp is not NULL.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_uefi.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
Alex Hung - May 9, 2013, 6:20 a.m.
On 05/07/2013 07:25 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID #997293, Dereference after null check (FORWARD_NULL)
>
> Coverity caught a bug where we are closing fp even if it failed
> to open.  Close it only if it opens correctly and fp is not NULL.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/lib/src/fwts_uefi.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/lib/src/fwts_uefi.c b/src/lib/src/fwts_uefi.c
> index 29cad80..f8678ab 100644
> --- a/src/lib/src/fwts_uefi.c
> +++ b/src/lib/src/fwts_uefi.c
> @@ -107,8 +107,8 @@ static int fwts_uefi_get_interface(char **path)
>   					strcpy(efivar_path, "/sys/firmware/efi/vars");
>   			}
>   		}
> +		fclose(fp);
>   	}
> -	fclose(fp);
>
>   	*path = NULL;
>
>
Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu - May 16, 2013, 3:30 a.m.
On 05/07/2013 07:25 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID #997293, Dereference after null check (FORWARD_NULL)
>
> Coverity caught a bug where we are closing fp even if it failed
> to open.  Close it only if it opens correctly and fp is not NULL.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/lib/src/fwts_uefi.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/src/lib/src/fwts_uefi.c b/src/lib/src/fwts_uefi.c
> index 29cad80..f8678ab 100644
> --- a/src/lib/src/fwts_uefi.c
> +++ b/src/lib/src/fwts_uefi.c
> @@ -107,8 +107,8 @@ static int fwts_uefi_get_interface(char **path)
>   					strcpy(efivar_path, "/sys/firmware/efi/vars");
>   			}
>   		}
> +		fclose(fp);
>   	}
> -	fclose(fp);
>
>   	*path = NULL;
>
>

Acked-by: Ivan Hu <ivan.hu@canonical.com>

Patch

diff --git a/src/lib/src/fwts_uefi.c b/src/lib/src/fwts_uefi.c
index 29cad80..f8678ab 100644
--- a/src/lib/src/fwts_uefi.c
+++ b/src/lib/src/fwts_uefi.c
@@ -107,8 +107,8 @@  static int fwts_uefi_get_interface(char **path)
 					strcpy(efivar_path, "/sys/firmware/efi/vars");
 			}
 		}
+		fclose(fp);
 	}
-	fclose(fp);
 
 	*path = NULL;