From patchwork Sun Nov 4 22:19:41 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin Ian King X-Patchwork-Id: 197101 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from chlorine.canonical.com (chlorine.canonical.com [91.189.94.204]) by ozlabs.org (Postfix) with ESMTP id 1368A2C017D for ; Mon, 5 Nov 2012 09:19:55 +1100 (EST) Received: from localhost ([127.0.0.1] helo=chlorine.canonical.com) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1TV8Xp-00018v-Qo; Sun, 04 Nov 2012 22:19:53 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1TV8Xn-00018A-W4 for fwts-devel@lists.ubuntu.com; Sun, 04 Nov 2012 22:19:52 +0000 Received: from cpc3-craw6-2-0-cust180.croy.cable.virginmedia.com ([77.100.248.181] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1TV8Xn-0000Ll-Sz for fwts-devel@lists.ubuntu.com; Sun, 04 Nov 2012 22:19:51 +0000 From: Colin King To: fwts-devel@lists.ubuntu.com Subject: [PATCH 03/12] lib: fwts_args: use strncpy, strncat instead of strcpy, strcat Date: Sun, 4 Nov 2012 22:19:41 +0000 Message-Id: <1352067590-11820-4-git-send-email-colin.king@canonical.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1352067590-11820-1-git-send-email-colin.king@canonical.com> References: <1352067590-11820-1-git-send-email-colin.king@canonical.com> X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.13 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: fwts-devel-bounces@lists.ubuntu.com Errors-To: fwts-devel-bounces@lists.ubuntu.com From: Colin Ian King Signed-off-by: Colin Ian King --- src/lib/src/fwts_args.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/lib/src/fwts_args.c b/src/lib/src/fwts_args.c index f2038ac..5e823d6 100644 --- a/src/lib/src/fwts_args.c +++ b/src/lib/src/fwts_args.c @@ -129,26 +129,27 @@ int fwts_args_parse(fwts_framework *fw, const int argc, char * const argv[]) if (short_name && (len = strlen(short_name)) > 0) { if (short_options) { - short_options = realloc(short_options, - short_options_len + len + 1); + size_t new_len = short_options_len + len + 1; + short_options = realloc(short_options, new_len); if (short_options == NULL) { fwts_log_error(fw, "Out of memory " "allocating options."); return FWTS_ERROR; } - strcat(short_options, short_name); + strncat(short_options, short_name, new_len); short_options_len += (len + 1); } else { - short_options = calloc(1, len + 1); + size_t new_len = len + 1; + short_options = calloc(1, new_len); if (short_options == NULL) { fwts_log_error(fw, "Out of memory " "allocating options."); return FWTS_ERROR; } - strcpy(short_options, short_name); - short_options_len += (len + 1); + strncpy(short_options, short_name, new_len); + short_options_len += new_len; } } } @@ -292,8 +293,8 @@ void fwts_args_show_options(void) } } } - strcat(ptr, "--"); - strcat(ptr, option->long_name); + strncat(ptr, "--", buffer - ptr); + strncat(ptr, option->long_name, buffer - ptr); fwts_args_show_option(width, buffer, option->explanation); }