From patchwork Thu Nov 22 14:52:30 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: 201060 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 6B3CF2C008C for ; Fri, 23 Nov 2012 01:52:34 +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 1TbY8n-0007eU-0g; Thu, 22 Nov 2012 14:52:33 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by chlorine.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1TbY8l-0007eP-L3 for fwts-devel@lists.ubuntu.com; Thu, 22 Nov 2012 14:52:31 +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 1TbY8l-0004e3-In for fwts-devel@lists.ubuntu.com; Thu, 22 Nov 2012 14:52:31 +0000 From: Colin King To: fwts-devel@lists.ubuntu.com Subject: [PATCH] lib: fwts_klog: Don't regex compile non-regex strings Date: Thu, 22 Nov 2012 14:52:30 +0000 Message-Id: <1353595950-27888-1-git-send-email-colin.king@canonical.com> X-Mailer: git-send-email 1.8.0 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 For some reason that I overlooked, I'm compiling non-regex strings which is plainly wrong. Fix this - just regex compile regex patterns and unsure the .re and .extra fields are NULL on error conditions and for non-regex expressions to bullet proof the code. Signed-off-by: Colin Ian King Acked-by: Keng-Yu Lin Acked-by: Ivan Hu --- src/lib/src/fwts_klog.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/src/lib/src/fwts_klog.c b/src/lib/src/fwts_klog.c index 54beae2..0a6350c 100644 --- a/src/lib/src/fwts_klog.c +++ b/src/lib/src/fwts_klog.c @@ -397,15 +397,22 @@ static int fwts_klog_check(fwts_framework *fw, if (patterns[i].label == NULL) goto fail; - if ((patterns[i].re = pcre_compile(patterns[i].pattern, 0, &error, &erroffset, NULL)) == NULL) { - fwts_log_error(fw, "Regex %s failed to compile: %s.", patterns[i].pattern, error); - patterns[i].re = NULL; - } else { - patterns[i].extra = pcre_study(patterns[i].re, 0, &error); - if (error != NULL) { - fwts_log_error(fw, "Regex %s failed to optimize: %s.", patterns[i].pattern, error); + if (patterns[i].compare_mode == FWTS_COMPARE_REGEX) { + if ((patterns[i].re = pcre_compile(patterns[i].pattern, 0, &error, &erroffset, NULL)) == NULL) { + fwts_log_error(fw, "Regex %s failed to compile: %s.", patterns[i].pattern, error); patterns[i].re = NULL; + patterns[i].extra = NULL; + } else { + patterns[i].extra = pcre_study(patterns[i].re, 0, &error); + if (error != NULL) { + fwts_log_error(fw, "Regex %s failed to optimize: %s.", patterns[i].pattern, error); + patterns[i].re = NULL; + patterns[i].extra = NULL; + } } + } else { + patterns[i].re = NULL; + patterns[i].extra = NULL; } } /* We've now collected up the scan patterns, lets scan the log for errors */