Patchwork lib: fwts_acpi_tables: handle fwts_low_realloc() failures

login
register
mail settings
Submitter Colin King
Date March 9, 2012, 1:04 a.m.
Message ID <1331255058-30417-1-git-send-email-colin.king@canonical.com>
Download mbox | patch
Permalink /patch/145637/
State Accepted
Headers show

Comments

Colin King - March 9, 2012, 1:04 a.m.
From: Colin Ian King <colin.king@canonical.com>

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_acpi_tables.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
Alex Hung - March 9, 2012, 1:56 a.m.
On 03/09/2012 09:04 AM, Colin King wrote:
> From: Colin Ian King<colin.king@canonical.com>
>
> Signed-off-by: Colin Ian King<colin.king@canonical.com>
> ---
>   src/lib/src/fwts_acpi_tables.c |    4 ++++
>   1 files changed, 4 insertions(+), 0 deletions(-)
>
> diff --git a/src/lib/src/fwts_acpi_tables.c b/src/lib/src/fwts_acpi_tables.c
> index 5b8887b..0a90d37 100644
> --- a/src/lib/src/fwts_acpi_tables.c
> +++ b/src/lib/src/fwts_acpi_tables.c
> @@ -349,6 +349,8 @@ static uint8_t *fwts_acpi_load_table_from_acpidump(FILE *fp, char *name, uint64_
>
>   		len += (n - 1);
>   		table = fwts_low_realloc(table, len);
> +		if (table == NULL)
> +			return NULL;
>   		memcpy(table + offset, data, n-1);
>   	}
>
> @@ -414,6 +416,8 @@ static uint8_t *fwts_acpi_load_table_from_file(const int fd, size_t *length)
>   		}
>   		else {
>   			ptr = (uint8_t*)fwts_low_realloc(ptr, size + n + 1);
> +			if (ptr == NULL)
> +				return NULL;
>   			memcpy(ptr + size, buffer, n);
>   			size += n;
>   		}
Acked-by: Alex Hung <alex.hung@canonical.com>
Keng-Yu Lin - March 9, 2012, 5:37 a.m.
On Fri, Mar 9, 2012 at 9:04 AM, Colin King <colin.king@canonical.com> wrote:
> From: Colin Ian King <colin.king@canonical.com>
>
> Signed-off-by: Colin Ian King <colin.king@canonical.com>
> ---
>  src/lib/src/fwts_acpi_tables.c |    4 ++++
>  1 files changed, 4 insertions(+), 0 deletions(-)
>
> diff --git a/src/lib/src/fwts_acpi_tables.c b/src/lib/src/fwts_acpi_tables.c
> index 5b8887b..0a90d37 100644
> --- a/src/lib/src/fwts_acpi_tables.c
> +++ b/src/lib/src/fwts_acpi_tables.c
> @@ -349,6 +349,8 @@ static uint8_t *fwts_acpi_load_table_from_acpidump(FILE *fp, char *name, uint64_
>
>                len += (n - 1);
>                table = fwts_low_realloc(table, len);
> +               if (table == NULL)
> +                       return NULL;
>                memcpy(table + offset, data, n-1);
>        }
>
> @@ -414,6 +416,8 @@ static uint8_t *fwts_acpi_load_table_from_file(const int fd, size_t *length)
>                }
>                else {
>                        ptr = (uint8_t*)fwts_low_realloc(ptr, size + n + 1);
> +                       if (ptr == NULL)
> +                               return NULL;
>                        memcpy(ptr + size, buffer, n);
>                        size += n;
>                }
> --
> 1.7.9
>
Acked-by: Keng-Yu Lin <kengyu@canonical.com>

Patch

diff --git a/src/lib/src/fwts_acpi_tables.c b/src/lib/src/fwts_acpi_tables.c
index 5b8887b..0a90d37 100644
--- a/src/lib/src/fwts_acpi_tables.c
+++ b/src/lib/src/fwts_acpi_tables.c
@@ -349,6 +349,8 @@  static uint8_t *fwts_acpi_load_table_from_acpidump(FILE *fp, char *name, uint64_
 
 		len += (n - 1);
 		table = fwts_low_realloc(table, len);
+		if (table == NULL)
+			return NULL;
 		memcpy(table + offset, data, n-1);
 	}
 
@@ -414,6 +416,8 @@  static uint8_t *fwts_acpi_load_table_from_file(const int fd, size_t *length)
 		}
 		else {
 			ptr = (uint8_t*)fwts_low_realloc(ptr, size + n + 1);
+			if (ptr == NULL)
+				return NULL;
 			memcpy(ptr + size, buffer, n);
 			size += n;
 		}