diff mbox

lib: fwts_memorymap: handle the case where str maybe NULL

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

Commit Message

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

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

str may be null, in which case we should only parse for end
and register a memory map line if str is not NULL.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_memorymap.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Alex Hung May 10, 2013, 12:48 a.m. UTC | #1
On 05/07/2013 07:32 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID #997294, Dereference after null check (FORWARD_NULL)
>
> str may be null, in which case we should only parse for end
> and register a memory map line if str is not NULL.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/lib/src/fwts_memorymap.c | 7 ++++---
>   1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/src/lib/src/fwts_memorymap.c b/src/lib/src/fwts_memorymap.c
> index 6e8bc1e..e619627 100644
> --- a/src/lib/src/fwts_memorymap.c
> +++ b/src/lib/src/fwts_memorymap.c
> @@ -185,11 +185,12 @@ static void fwts_memory_map_dmesg_info(void *data, void *private)
>
>   		start = strtoull(str+10, NULL, 16);
>   		str = strstr(line," - ");
> -		if (str)
> +		if (str) {
>   			str += 3;
> -		end   = strtoull(str, NULL, 16) - 1;
> +			end = strtoull(str, NULL, 16) - 1;
>
> -		fwts_register_memory_map_line(memory_map_list, start, end, fwts_memory_map_str_to_type(line));
> +			fwts_register_memory_map_line(memory_map_list, start, end, fwts_memory_map_str_to_type(line));
> +		}
>   	}
>   }
>
>
Acked-by: Alex Hung <alex.hung@canonical.com>
Ivan Hu May 16, 2013, 3:35 a.m. UTC | #2
On 05/07/2013 07:32 AM, Colin King wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Coverity CID #997294, Dereference after null check (FORWARD_NULL)
>
> str may be null, in which case we should only parse for end
> and register a memory map line if str is not NULL.
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>   src/lib/src/fwts_memorymap.c | 7 ++++---
>   1 file changed, 4 insertions(+), 3 deletions(-)
>
> diff --git a/src/lib/src/fwts_memorymap.c b/src/lib/src/fwts_memorymap.c
> index 6e8bc1e..e619627 100644
> --- a/src/lib/src/fwts_memorymap.c
> +++ b/src/lib/src/fwts_memorymap.c
> @@ -185,11 +185,12 @@ static void fwts_memory_map_dmesg_info(void *data, void *private)
>
>   		start = strtoull(str+10, NULL, 16);
>   		str = strstr(line," - ");
> -		if (str)
> +		if (str) {
>   			str += 3;
> -		end   = strtoull(str, NULL, 16) - 1;
> +			end = strtoull(str, NULL, 16) - 1;
>
> -		fwts_register_memory_map_line(memory_map_list, start, end, fwts_memory_map_str_to_type(line));
> +			fwts_register_memory_map_line(memory_map_list, start, end, fwts_memory_map_str_to_type(line));
> +		}
>   	}
>   }
>
>

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

Patch

diff --git a/src/lib/src/fwts_memorymap.c b/src/lib/src/fwts_memorymap.c
index 6e8bc1e..e619627 100644
--- a/src/lib/src/fwts_memorymap.c
+++ b/src/lib/src/fwts_memorymap.c
@@ -185,11 +185,12 @@  static void fwts_memory_map_dmesg_info(void *data, void *private)
 
 		start = strtoull(str+10, NULL, 16);
 		str = strstr(line," - ");
-		if (str)
+		if (str) {
 			str += 3;
-		end   = strtoull(str, NULL, 16) - 1;
+			end = strtoull(str, NULL, 16) - 1;
 
-		fwts_register_memory_map_line(memory_map_list, start, end, fwts_memory_map_str_to_type(line));
+			fwts_register_memory_map_line(memory_map_list, start, end, fwts_memory_map_str_to_type(line));
+		}
 	}
 }