[PATCH] lib: fwts_klog: Don't regex compile non-regex strings

Keng-Yu Lin kengyu at canonical.com
Tue Nov 27 08:08:06 UTC 2012


On Thu, Nov 22, 2012 at 10:52 PM, Colin King <colin.king at canonical.com> wrote:
> From: Colin Ian King <colin.king at canonical.com>
>
> 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 <colin.king at canonical.com>
> ---
>  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 */
> --
> 1.8.0
>
Acked-by: Keng-Yu Lin <kengyu at canonical.com>



More information about the fwts-devel mailing list