Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5b354d2

Browse files
committed
Fixes:
1 Report error message instead of do nothing in case of error in regex2 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 <moje@kalhotky.net>)
1 parente248016 commit5b354d2

File tree

2 files changed

+20
-13
lines changed

2 files changed

+20
-13
lines changed

‎contrib/tsearch2/ispell/spell.c

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
#defineMAX_NORM 1024
1111
#defineMAXNORMLEN 256
1212

13+
#defineERRSTRSIZE1024
14+
1315
#defineSTRNCASECMP(x,y)pg_strncasecmp(x, y, strlen(y))
1416
#defineGETWCHAR(W,L,N,T) ( ((uint8*)(W))[ ((T)==FF_PREFIX) ? (N) : ( (L) - 1 - (N) ) ] )
1517
#defineGETCHAR(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
250252
{
251253
Conf->Affix[Conf->naffixes].issimple=1;
252254
Conf->Affix[Conf->naffixes].isregis=0;
253-
*(Conf->Affix[Conf->naffixes].mask)='\0';
255+
Conf->Affix[Conf->naffixes].mask=strdup("");
254256
}
255257
elseif (RS_isRegis(mask))
256258
{
257259
Conf->Affix[Conf->naffixes].issimple=0;
258260
Conf->Affix[Conf->naffixes].isregis=1;
259-
strcpy(Conf->Affix[Conf->naffixes].mask,mask);
261+
Conf->Affix[Conf->naffixes].mask=strdup(mask);
260262
}
261263
else
262264
{
263265
Conf->Affix[Conf->naffixes].issimple=0;
264266
Conf->Affix[Conf->naffixes].isregis=0;
267+
Conf->Affix[Conf->naffixes].mask= (char*)malloc(strlen(mask)+2 );
265268
if (type==FF_SUFFIX)
266269
sprintf(Conf->Affix[Conf->naffixes].mask,"%s$",mask);
267270
else
268271
sprintf(Conf->Affix[Conf->naffixes].mask,"^%s",mask);
269272
}
273+
MEMOUT(Conf->Affix[Conf->naffixes].mask);
274+
270275
Conf->Affix[Conf->naffixes].compile=1;
271276
Conf->Affix[Conf->naffixes].flagflags=flagflags;
272277
Conf->Affix[Conf->naffixes].flag=flag;
273278
Conf->Affix[Conf->naffixes].type=type;
274279

275-
strcpy(Conf->Affix[Conf->naffixes].find,find);
276-
strcpy(Conf->Affix[Conf->naffixes].repl,repl);
280+
Conf->Affix[Conf->naffixes].find=strdup(find);
281+
MEMOUT(Conf->Affix[Conf->naffixes].find);
282+
Conf->Affix[Conf->naffixes].repl=strdup(repl);
283+
MEMOUT(Conf->Affix[Conf->naffixes].repl);
277284
Conf->Affix[Conf->naffixes].replen=strlen(repl);
278285
Conf->naffixes++;
279286
return (0);
@@ -794,12 +801,9 @@ CheckAffix(const char *word, size_t len, AFFIX * Affix, char flagflags, char *ne
794801
pfree(mask);
795802
if (err)
796803
{
797-
/*
798-
* regerror(err, &(Affix->reg.regex), regerrstr,
799-
* ERRSTRSIZE);
800-
*/
801-
pg_regfree(&(Affix->reg.regex));
802-
return (NULL);
804+
charregerrstr[ERRSTRSIZE];
805+
pg_regerror(err,&(Affix->reg.regex),regerrstr,ERRSTRSIZE);
806+
elog(ERROR,"Regex error in '%s': %s",Affix->mask,regerrstr);
803807
}
804808
Affix->compile=0;
805809
}
@@ -1239,6 +1243,9 @@ NIFree(IspellDict * Conf)
12391243
else
12401244
pg_regfree(&(Affix[i].reg.regex));
12411245
}
1246+
free(Affix[i].mask);
1247+
free(Affix[i].find);
1248+
free(Affix[i].repl);
12421249
}
12431250
if (Conf->Spell)
12441251
{

‎contrib/tsearch2/ispell/spell.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ typedef struct aff_struct
5454
isregis:1,
5555
unused:1,
5656
replen:16;
57-
charmask[32];
58-
charfind[16];
59-
charrepl[16];
57+
char*mask;
58+
char*find;
59+
char*repl;
6060
union
6161
{
6262
regex_tregex;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp