diff mbox

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

Message ID 1367882708-21822-1-git-send-email-colin.king@canonical.com
State Accepted
Headers show

Commit Message

Colin Ian King May 6, 2013, 11:25 p.m. UTC
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(-)

Comments

Alex Hung May 9, 2013, 6:20 a.m. UTC | #1
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. UTC | #2
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>
diff mbox

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;