From patchwork Sun Nov 4 22:19:42 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: 197102 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 5AA042C014C for ; Mon, 5 Nov 2012 09:19:56 +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 1TV8Xr-00019K-5u; Sun, 04 Nov 2012 22:19:55 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1TV8Xo-00018S-Fm 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 1TV8Xo-0000Lo-CC for fwts-devel@lists.ubuntu.com; Sun, 04 Nov 2012 22:19:52 +0000 From: Colin King To: fwts-devel@lists.ubuntu.com Subject: [PATCH 04/12] lib: fwts_log: use strncpy, strncat instead of strcpy, strcat Date: Sun, 4 Nov 2012 22:19:42 +0000 Message-Id: <1352067590-11820-5-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_log.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/lib/src/fwts_log.c b/src/lib/src/fwts_log.c index 63983d5..6e5e169 100644 --- a/src/lib/src/fwts_log.c +++ b/src/lib/src/fwts_log.c @@ -337,7 +337,7 @@ static char *fwts_log_filename(const char *filename, const fwts_log_type type) char *suffix; size_t suffix_len; size_t trunc_len; - size_t filename_len; + size_t new_len; struct stat stat_buf; /* @@ -368,12 +368,13 @@ static char *fwts_log_filename(const char *filename, const fwts_log_type type) !strcmp(ptr, ".html"))) { trunc_len = ptr - filename; - if ((new_name = calloc(trunc_len + suffix_len + 1, 1)) == NULL) { + new_len = trunc_len + suffix_len + 1; + if ((new_name = calloc(new_len, 1)) == NULL) { fprintf(stderr, "Cannot allocate log name.\n"); return NULL; } strncpy(new_name, filename, trunc_len); - strcat(new_name, suffix); /* strcat OK because calloc zero'd all of new_name */ + strncat(new_name, suffix, new_len); /* strncat OK because calloc zero'd all of new_name */ return new_name; } @@ -381,14 +382,14 @@ static char *fwts_log_filename(const char *filename, const fwts_log_type type) * We didn't find a suffix or a known suffix, so append * the appropriate one to the given log filename */ - filename_len = strlen(filename); - if ((new_name = calloc(filename_len + suffix_len + 1, 1)) == NULL) { + new_len = strlen(filename) + suffix_len + 1; + if ((new_name = calloc(new_len, 1)) == NULL) { fprintf(stderr, "Cannot allocate log name.\n"); return NULL; } - strcpy(new_name, filename); - strcat(new_name, suffix); + strncpy(new_name, filename, new_len); + strncat(new_name, suffix, new_len); return new_name; } @@ -588,15 +589,15 @@ char *fwts_log_get_filenames(const char *filename, const fwts_log_type type) free(tmp); return NULL; } - strcat(filenames, " "); - strcat(filenames, tmp); + strncat(filenames, " ", len); + strncat(filenames, tmp, len); } else { len = strlen(tmp) + 1; if ((filenames = malloc(len)) == NULL) { free(tmp); return NULL; } - strcpy(filenames, tmp); + strncpy(filenames, tmp, len); } free(tmp); }