dmi: dmicheck: zero buffer buf, cleans up a static analysis warning

Message ID 20171110174831.1056-1-colin.king@canonical.com
State Accepted
Headers show
Series
  • dmi: dmicheck: zero buffer buf, cleans up a static analysis warning
Related show

Commit Message

Colin King Nov. 10, 2017, 5:48 p.m.
From: Colin Ian King <colin.king@canonical.com>

This is not strictly necessary, but it cleans up a static analysis warning
from CoverityScan.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/dmi/dmicheck/dmicheck.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

Alex Hung Nov. 13, 2017, 3:29 a.m. | #1
On 2017-11-11 01:48 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> This is not strictly necessary, but it cleans up a static analysis warning
> from CoverityScan.
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/dmi/dmicheck/dmicheck.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/src/dmi/dmicheck/dmicheck.c b/src/dmi/dmicheck/dmicheck.c
> index a55597f1..9bc8804c 100644
> --- a/src/dmi/dmicheck/dmicheck.c
> +++ b/src/dmi/dmicheck/dmicheck.c
> @@ -306,6 +306,8 @@ static int dmi_load_file(const char* filename, void *buf, size_t size)
>   	int fd;
>   	ssize_t ret;
>   
> +	(void)memset(buf, 0, size);
> +
>   	if ((fd = open(filename, O_RDONLY)) < 0)
>   		return FWTS_ERROR;
>   	ret = read(fd, buf, size);
> 


Acked-by: Alex Hung <alex.hung@canonical.com>
ivanhu Nov. 15, 2017, 9:43 a.m. | #2
On 11/11/2017 01:48 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
> 
> This is not strictly necessary, but it cleans up a static analysis warning
> from CoverityScan.
> 
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/dmi/dmicheck/dmicheck.c | 2 ++
>   1 file changed, 2 insertions(+)
> 
> diff --git a/src/dmi/dmicheck/dmicheck.c b/src/dmi/dmicheck/dmicheck.c
> index a55597f1..9bc8804c 100644
> --- a/src/dmi/dmicheck/dmicheck.c
> +++ b/src/dmi/dmicheck/dmicheck.c
> @@ -306,6 +306,8 @@ static int dmi_load_file(const char* filename, void *buf, size_t size)
>   	int fd;
>   	ssize_t ret;
>   
> +	(void)memset(buf, 0, size);
> +
>   	if ((fd = open(filename, O_RDONLY)) < 0)
>   		return FWTS_ERROR;
>   	ret = read(fd, buf, size);
> 

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

Patch

diff --git a/src/dmi/dmicheck/dmicheck.c b/src/dmi/dmicheck/dmicheck.c
index a55597f1..9bc8804c 100644
--- a/src/dmi/dmicheck/dmicheck.c
+++ b/src/dmi/dmicheck/dmicheck.c
@@ -306,6 +306,8 @@  static int dmi_load_file(const char* filename, void *buf, size_t size)
 	int fd;
 	ssize_t ret;
 
+	(void)memset(buf, 0, size);
+
 	if ((fd = open(filename, O_RDONLY)) < 0)
 		return FWTS_ERROR;
 	ret = read(fd, buf, size);