From 748b44354889329f8c0ef0b9c86013a80f195be2 Mon Sep 17 00:00:00 2001 From: Zhifeng, Cai Date: Sun, 6 Mar 2011 21:39:10 -0800 Subject: [PATCH 23/51] lldpad: malloc could fail in clif_attach_helper() malloc() may fail in clif_attach_helper() so return values must be checked. Suggested-By: Zhifeng, Cai Signed-off-by: John Fastabend Signed-off-by: Petr Sabata --- clif.c | 6 ++++++ 1 files changed, 6 insertions(+), 0 deletions(-) diff --git a/clif.c b/clif.c index 20885f6..9e256f2 100644 --- a/clif.c +++ b/clif.c @@ -165,12 +165,18 @@ static int clif_attach_helper(struct clif *clif, char *tlvs_hex, int attach) /* Allocate maximum buffer usage */ if (tlvs_hex && attach) { buf = malloc(sizeof(char)*(strlen(tlvs_hex) + 1)); + if (!buf) + return -1; sprintf(buf, "%s%s","A",tlvs_hex); } else if (attach) { buf = malloc(sizeof(char) * 2); + if (!buf) + return -1; sprintf(buf, "A"); } else { buf = malloc(sizeof(char) * 2); + if (!buf) + return -1; sprintf(buf, "D"); } -- 1.7.4.4