Patchwork lib: fwts_pipeio: handle realloc failure

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

Comments

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

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_pipeio.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
Alex Hung - March 9, 2012, 1:45 a.m.
On 03/09/2012 09:10 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_pipeio.c |    2 ++
>   1 files changed, 2 insertions(+), 0 deletions(-)
>
> diff --git a/src/lib/src/fwts_pipeio.c b/src/lib/src/fwts_pipeio.c
> index 7577beb..d4abfd5 100644
> --- a/src/lib/src/fwts_pipeio.c
> +++ b/src/lib/src/fwts_pipeio.c
> @@ -98,6 +98,8 @@ char *fwts_pipe_read(const int fd, ssize_t *length)
>   		}
>   		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:35 a.m.
On Fri, Mar 9, 2012 at 9:10 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_pipeio.c |    2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)
>
> diff --git a/src/lib/src/fwts_pipeio.c b/src/lib/src/fwts_pipeio.c
> index 7577beb..d4abfd5 100644
> --- a/src/lib/src/fwts_pipeio.c
> +++ b/src/lib/src/fwts_pipeio.c
> @@ -98,6 +98,8 @@ char *fwts_pipe_read(const int fd, ssize_t *length)
>                }
>                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>

Patch

diff --git a/src/lib/src/fwts_pipeio.c b/src/lib/src/fwts_pipeio.c
index 7577beb..d4abfd5 100644
--- a/src/lib/src/fwts_pipeio.c
+++ b/src/lib/src/fwts_pipeio.c
@@ -98,6 +98,8 @@  char *fwts_pipe_read(const int fd, ssize_t *length)
 		}
 		else {
 			ptr = realloc(ptr, size + n + 1);
+			if (ptr == NULL)
+				return NULL;
 			memcpy(ptr + size, buffer, n);
 			size += n;
 			*(ptr+size) = 0;