Patchwork acpica: handle realloc failures in fwts_acpica_vprintf()

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

Comments

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

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/acpica/fwts_acpica.c |   10 ++++++++--
 1 files changed, 8 insertions(+), 2 deletions(-)
Alex Hung - March 9, 2012, 2:12 a.m.
On 03/09/2012 08:59 AM, Colin King wrote:
> From: Colin Ian King<colin.king@canonical.com>
>
> Signed-off-by: Colin Ian King<colin.king@canonical.com>
> ---
>   src/acpica/fwts_acpica.c |   10 ++++++++--
>   1 files changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/src/acpica/fwts_acpica.c b/src/acpica/fwts_acpica.c
> index 096683a..609dc8f 100644
> --- a/src/acpica/fwts_acpica.c
> +++ b/src/acpica/fwts_acpica.c
> @@ -277,11 +277,17 @@ void fwts_acpica_vprintf(const char *fmt, va_list args)
>   	if (buffer_len == 0) {
>   		buffer_len = tmp_len + 1;
>   		buffer = malloc(buffer_len);
> -		strcpy(buffer, tmp);
> +		if (buffer)
> +			strcpy(buffer, tmp);
> +		else
> +			buffer_len = 0;
>   	} else {
>   		buffer_len += tmp_len;
>   		buffer = realloc(buffer, buffer_len);
> -		strcat(buffer, tmp);
> +		if (buffer)
> +			strcat(buffer, tmp);
> +		else
> +			buffer_len = 0;
>   	}
>   	
>   	if (index(buffer, '\n') != NULL) {
Acked-by: Alex Hung <alex.hung@canonical.com>
Keng-Yu Lin - March 9, 2012, 5:38 a.m.
On Fri, Mar 9, 2012 at 8:59 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/acpica/fwts_acpica.c |   10 ++++++++--
>  1 files changed, 8 insertions(+), 2 deletions(-)
>
> diff --git a/src/acpica/fwts_acpica.c b/src/acpica/fwts_acpica.c
> index 096683a..609dc8f 100644
> --- a/src/acpica/fwts_acpica.c
> +++ b/src/acpica/fwts_acpica.c
> @@ -277,11 +277,17 @@ void fwts_acpica_vprintf(const char *fmt, va_list args)
>        if (buffer_len == 0) {
>                buffer_len = tmp_len + 1;
>                buffer = malloc(buffer_len);
> -               strcpy(buffer, tmp);
> +               if (buffer)
> +                       strcpy(buffer, tmp);
> +               else
> +                       buffer_len = 0;
>        } else {
>                buffer_len += tmp_len;
>                buffer = realloc(buffer, buffer_len);
> -               strcat(buffer, tmp);
> +               if (buffer)
> +                       strcat(buffer, tmp);
> +               else
> +                       buffer_len = 0;
>        }
>
>        if (index(buffer, '\n') != NULL) {
> --
> 1.7.9
>
Acked-by: Keng-Yu Lin <kengyu@canonical.com>

Patch

diff --git a/src/acpica/fwts_acpica.c b/src/acpica/fwts_acpica.c
index 096683a..609dc8f 100644
--- a/src/acpica/fwts_acpica.c
+++ b/src/acpica/fwts_acpica.c
@@ -277,11 +277,17 @@  void fwts_acpica_vprintf(const char *fmt, va_list args)
 	if (buffer_len == 0) {
 		buffer_len = tmp_len + 1;
 		buffer = malloc(buffer_len);
-		strcpy(buffer, tmp);
+		if (buffer)
+			strcpy(buffer, tmp);
+		else
+			buffer_len = 0;
 	} else {
 		buffer_len += tmp_len;
 		buffer = realloc(buffer, buffer_len);
-		strcat(buffer, tmp);
+		if (buffer)
+			strcat(buffer, tmp);
+		else
+			buffer_len = 0;
 	}
 	
 	if (index(buffer, '\n') != NULL) {