pgpool2.git / summary / log / commit / refs

commit    2714c68c7e320f4a036d2a68d416e85483358d2e
Author:   Tatsuo Ishii <ishii@postgresql.org>
Date:     Tue Sep 16 23:30:43 2014 +0000

    Fix add_regex_array.
    
    It addresses out of the array range if empty string is given.
    Also use pre computed string length to save a few cycle.


src/utils/regex_array.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/utils/regex_array.c b/src/utils/regex_array.c index a86a812d9..2d96b6171 100644 --- a/src/utils/regex_array.c +++ b/src/utils/regex_array.c @@ -84,7 +84,7 @@ int add_regex_array(RegArray *ar, char *pattern) /* Add extended regex search */ regex_flags |= REG_EXTENDED; - pat = palloc(sizeof(char)*(strlen(pattern)+3)); + pat = palloc(sizeof(char)*(len+3)); if (strncmp(pattern, "^", 1) != 0) { strncpy(pat, "^", 2); @@ -95,7 +95,7 @@ int add_regex_array(RegArray *ar, char *pattern) strncpy(pat, pattern, len + 1); } - if (pattern[len - 1] != '$') + if (len > 0 && pattern[len - 1] != '$') { strncat(pat, "$", 2); } [parent: a2511ed765f0]