From 5b354d2c7e318f8fa6b81cd83769d91c4bc409af Mon Sep 17 00:00:00 2001 From: Teodor Sigaev Date: Tue, 11 Jan 2005 16:07:55 +0000 Subject: [PATCH] Fixes: 1 Report error message instead of do nothing in case of error in regex 2 Malloced storage for mask, find and repl part of Affix. This parts may be large enough in real life (for example in czech, thanks to moje ) --- contrib/tsearch2/ispell/spell.c | 27 +++++++++++++++++---------- contrib/tsearch2/ispell/spell.h | 6 +++--- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/contrib/tsearch2/ispell/spell.c b/contrib/tsearch2/ispell/spell.c index c5783236b6..54b01e8ed7 100644 --- a/contrib/tsearch2/ispell/spell.c +++ b/contrib/tsearch2/ispell/spell.c @@ -10,6 +10,8 @@ #define MAX_NORM 1024 #define MAXNORMLEN 256 +#define ERRSTRSIZE 1024 + #define STRNCASECMP(x,y) pg_strncasecmp(x, y, strlen(y)) #define GETWCHAR(W,L,N,T) ( ((uint8*)(W))[ ((T)==FF_PREFIX) ? (N) : ( (L) - 1 - (N) ) ] ) #define GETCHAR(A,N,T) GETWCHAR( (A)->repl, (A)->replen, N, T ) @@ -250,30 +252,35 @@ NIAddAffix(IspellDict * Conf, int flag, char flagflags, const char *mask, const { Conf->Affix[Conf->naffixes].issimple = 1; Conf->Affix[Conf->naffixes].isregis = 0; - *(Conf->Affix[Conf->naffixes].mask) = '\0'; + Conf->Affix[Conf->naffixes].mask = strdup(""); } else if (RS_isRegis(mask)) { Conf->Affix[Conf->naffixes].issimple = 0; Conf->Affix[Conf->naffixes].isregis = 1; - strcpy(Conf->Affix[Conf->naffixes].mask, mask); + Conf->Affix[Conf->naffixes].mask = strdup(mask); } else { Conf->Affix[Conf->naffixes].issimple = 0; Conf->Affix[Conf->naffixes].isregis = 0; + Conf->Affix[Conf->naffixes].mask = (char*)malloc( strlen(mask) + 2 ); if (type == FF_SUFFIX) sprintf(Conf->Affix[Conf->naffixes].mask, "%s$", mask); else sprintf(Conf->Affix[Conf->naffixes].mask, "^%s", mask); } + MEMOUT(Conf->Affix[Conf->naffixes].mask); + Conf->Affix[Conf->naffixes].compile = 1; Conf->Affix[Conf->naffixes].flagflags = flagflags; Conf->Affix[Conf->naffixes].flag = flag; Conf->Affix[Conf->naffixes].type = type; - strcpy(Conf->Affix[Conf->naffixes].find, find); - strcpy(Conf->Affix[Conf->naffixes].repl, repl); + Conf->Affix[Conf->naffixes].find = strdup(find); + MEMOUT(Conf->Affix[Conf->naffixes].find); + Conf->Affix[Conf->naffixes].repl = strdup(repl); + MEMOUT(Conf->Affix[Conf->naffixes].repl); Conf->Affix[Conf->naffixes].replen = strlen(repl); Conf->naffixes++; return (0); @@ -794,12 +801,9 @@ CheckAffix(const char *word, size_t len, AFFIX * Affix, char flagflags, char *ne pfree(mask); if (err) { - /* - * regerror(err, &(Affix->reg.regex), regerrstr, - * ERRSTRSIZE); - */ - pg_regfree(&(Affix->reg.regex)); - return (NULL); + char regerrstr[ERRSTRSIZE]; + pg_regerror(err, &(Affix->reg.regex), regerrstr, ERRSTRSIZE); + elog(ERROR, "Regex error in '%s': %s", Affix->mask, regerrstr); } Affix->compile = 0; } @@ -1239,6 +1243,9 @@ NIFree(IspellDict * Conf) else pg_regfree(&(Affix[i].reg.regex)); } + free(Affix[i].mask); + free(Affix[i].find); + free(Affix[i].repl); } if (Conf->Spell) { diff --git a/contrib/tsearch2/ispell/spell.h b/contrib/tsearch2/ispell/spell.h index 44f1e7be08..cc7935fd74 100644 --- a/contrib/tsearch2/ispell/spell.h +++ b/contrib/tsearch2/ispell/spell.h @@ -54,9 +54,9 @@ typedef struct aff_struct isregis:1, unused:1, replen:16; - char mask[32]; - char find[16]; - char repl[16]; + char *mask; + char *find; + char *repl; union { regex_t regex;