diff mbox

lib: acpid: handle realloc failures in fwts_acpi_event_read()

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

Commit Message

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

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_acpid.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)

Comments

Alex Hung March 9, 2012, 1:56 a.m. UTC | #1
On 03/09/2012 09:06 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_acpid.c |    2 ++
>   1 files changed, 2 insertions(+), 0 deletions(-)
>
> diff --git a/src/lib/src/fwts_acpid.c b/src/lib/src/fwts_acpid.c
> index caaf157..6952276 100644
> --- a/src/lib/src/fwts_acpid.c
> +++ b/src/lib/src/fwts_acpid.c
> @@ -103,6 +103,8 @@ char *fwts_acpi_event_read(const int fd, size_t *length, const int timeout)
>   		}
>   		else {
>   			ptr = realloc(ptr, size + n + 1);
> +			if (ptr == NULL)
> +				return NULL;
>   			memcpy(ptr + size, buffer, n);
>   			size += n;
>   			*(ptr+size) = 0;
Acked-by: Alex Hung <alex.hung@canonical.com>
Keng-Yu Lin March 9, 2012, 5:36 a.m. UTC | #2
On Fri, Mar 9, 2012 at 9:06 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_acpid.c |    2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)
>
> diff --git a/src/lib/src/fwts_acpid.c b/src/lib/src/fwts_acpid.c
> index caaf157..6952276 100644
> --- a/src/lib/src/fwts_acpid.c
> +++ b/src/lib/src/fwts_acpid.c
> @@ -103,6 +103,8 @@ char *fwts_acpi_event_read(const int fd, size_t *length, const int timeout)
>                }
>                else {
>                        ptr = realloc(ptr, size + n + 1);
> +                       if (ptr == NULL)
> +                               return NULL;
>                        memcpy(ptr + size, buffer, n);
>                        size += n;
>                        *(ptr+size) = 0;
> --
> 1.7.9
>
Acked-by: Keng-Yu Lin <kengyu@canonical.com>
diff mbox

Patch

diff --git a/src/lib/src/fwts_acpid.c b/src/lib/src/fwts_acpid.c
index caaf157..6952276 100644
--- a/src/lib/src/fwts_acpid.c
+++ b/src/lib/src/fwts_acpid.c
@@ -103,6 +103,8 @@  char *fwts_acpi_event_read(const int fd, size_t *length, const int timeout)
 		}
 		else {
 			ptr = realloc(ptr, size + n + 1);
+			if (ptr == NULL)
+				return NULL;
 			memcpy(ptr + size, buffer, n);
 			size += n;
 			*(ptr+size) = 0;