Patchwork lib: fwts_args: handle realloc failure

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

Comments

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

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 src/lib/src/fwts_args.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
Alex Hung - March 9, 2012, 1:52 a.m.
On 03/09/2012 09:08 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_args.c |    6 ++++++
>   1 files changed, 6 insertions(+), 0 deletions(-)
>
> diff --git a/src/lib/src/fwts_args.c b/src/lib/src/fwts_args.c
> index f72561c..90f3d70 100644
> --- a/src/lib/src/fwts_args.c
> +++ b/src/lib/src/fwts_args.c
> @@ -127,6 +127,12 @@ int fwts_args_parse(fwts_framework *fw, int argc, char * const argv[])
>   				if (short_options) {
>   					short_options = realloc(short_options,
>   						strlen(short_options) + len + 1);
> +					if (short_options == NULL) {
> +						fwts_log_error(fw,
> +							"Out of memory "
> +							"allocating options.");
> +						return FWTS_ERROR;
> +					}
>   					strcat(short_options, short_name);
>   				} else {
>   					short_options = calloc(1, len + 1);
Acked-by: Alex Hung <alex.hung@canonical.com>
Keng-Yu Lin - March 9, 2012, 5:36 a.m.
On Fri, Mar 9, 2012 at 9:08 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_args.c |    6 ++++++
>  1 files changed, 6 insertions(+), 0 deletions(-)
>
> diff --git a/src/lib/src/fwts_args.c b/src/lib/src/fwts_args.c
> index f72561c..90f3d70 100644
> --- a/src/lib/src/fwts_args.c
> +++ b/src/lib/src/fwts_args.c
> @@ -127,6 +127,12 @@ int fwts_args_parse(fwts_framework *fw, int argc, char * const argv[])
>                                if (short_options) {
>                                        short_options = realloc(short_options,
>                                                strlen(short_options) + len + 1);
> +                                       if (short_options == NULL) {
> +                                               fwts_log_error(fw,
> +                                                       "Out of memory "
> +                                                       "allocating options.");
> +                                               return FWTS_ERROR;
> +                                       }
>                                        strcat(short_options, short_name);
>                                } else {
>                                        short_options = calloc(1, len + 1);
> --
> 1.7.9
>
Acked-by: Keng-Yu Lin <kengyu@canonical.com>

Patch

diff --git a/src/lib/src/fwts_args.c b/src/lib/src/fwts_args.c
index f72561c..90f3d70 100644
--- a/src/lib/src/fwts_args.c
+++ b/src/lib/src/fwts_args.c
@@ -127,6 +127,12 @@  int fwts_args_parse(fwts_framework *fw, int argc, char * const argv[])
 				if (short_options) {
 					short_options = realloc(short_options,
 						strlen(short_options) + len + 1);
+					if (short_options == NULL) {
+						fwts_log_error(fw,
+							"Out of memory "
+							"allocating options.");
+						return FWTS_ERROR;
+					}
 					strcat(short_options, short_name);
 				} else {
 					short_options = calloc(1, len + 1);