Patchwork uefi: uefidump: handle realloc failure

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

Comments

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

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/uefi/uefidump/uefidump.c |    2 ++
 1 files changed, 2 insertions(+), 0 deletions(-)
Alex Hung - March 9, 2012, 1:42 a.m.
On 03/09/2012 09:13 AM, Colin King wrote:
> From: Colin Ian King<colin.king@canonical.com>
>
> Signed-off-by: Colin Ian King<colin.king@canonical.com>
> ---
>   src/uefi/uefidump/uefidump.c |    2 ++
>   1 files changed, 2 insertions(+), 0 deletions(-)
>
> diff --git a/src/uefi/uefidump/uefidump.c b/src/uefi/uefidump/uefidump.c
> index a08b629..1f71107 100644
> --- a/src/uefi/uefidump/uefidump.c
> +++ b/src/uefi/uefidump/uefidump.c
> @@ -50,6 +50,8 @@ static char *uefidump_vprintf(char *str, const char *fmt, ...)
>   		str = strdup(buffer);
>   	else {
>   		str = realloc(str, strlen(str) + strlen(buffer) + 1);
> +		if (str == NULL)
> +			return NULL;
>   		strcat(str, buffer);
>   	}
>
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:13 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/uefi/uefidump/uefidump.c |    2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)
>
> diff --git a/src/uefi/uefidump/uefidump.c b/src/uefi/uefidump/uefidump.c
> index a08b629..1f71107 100644
> --- a/src/uefi/uefidump/uefidump.c
> +++ b/src/uefi/uefidump/uefidump.c
> @@ -50,6 +50,8 @@ static char *uefidump_vprintf(char *str, const char *fmt, ...)
>                str = strdup(buffer);
>        else {
>                str = realloc(str, strlen(str) + strlen(buffer) + 1);
> +               if (str == NULL)
> +                       return NULL;
>                strcat(str, buffer);
>        }
>
> --
> 1.7.9
>
Acked-by: Keng-Yu Lin <kengyu@canonical.com>

Patch

diff --git a/src/uefi/uefidump/uefidump.c b/src/uefi/uefidump/uefidump.c
index a08b629..1f71107 100644
--- a/src/uefi/uefidump/uefidump.c
+++ b/src/uefi/uefidump/uefidump.c
@@ -50,6 +50,8 @@  static char *uefidump_vprintf(char *str, const char *fmt, ...)
 		str = strdup(buffer);
 	else {
 		str = realloc(str, strlen(str) + strlen(buffer) + 1);
+		if (str == NULL)
+			return NULL;
 		strcat(str, buffer);
 	}