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

Commit89b3c6c

Browse files
committed
Fix one-byte buffer overrun in contrib/test_parser.
The original coding examined the next character before verifying thatthere *is* a next character. In the worst case with the input bufferright up against the end of memory, this would result in a segfault.Problem spotted by Paul Guyot; this commit extends his patch to fix anadditional case. In addition, make the code a tad more readable by notoverloading the usage of *tlen.
1 parent743ed08 commit89b3c6c

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

‎contrib/test_parser/test_parser.c

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,31 +73,32 @@ testprs_getlexeme(PG_FUNCTION_ARGS)
7373
ParserState*pst= (ParserState*)PG_GETARG_POINTER(0);
7474
char**t= (char**)PG_GETARG_POINTER(1);
7575
int*tlen= (int*)PG_GETARG_POINTER(2);
76+
intstartpos=pst->pos;
7677
inttype;
7778

78-
*tlen=pst->pos;
7979
*t=pst->buffer+pst->pos;
8080

81-
if ((pst->buffer)[pst->pos]==' ')
81+
if (pst->pos<pst->len&&
82+
(pst->buffer)[pst->pos]==' ')
8283
{
8384
/* blank type */
8485
type=12;
85-
/* go to the next non-white-space character */
86-
while ((pst->buffer)[pst->pos]==' '&&
87-
pst->pos<pst->len)
86+
/* go to the next non-space character */
87+
while (pst->pos<pst->len&&
88+
(pst->buffer)[pst->pos]==' ')
8889
(pst->pos)++;
8990
}
9091
else
9192
{
9293
/* word type */
9394
type=3;
94-
/* go to the nextwhite-space character */
95-
while ((pst->buffer)[pst->pos]!=' '&&
96-
pst->pos<pst->len)
95+
/* go to the next space character */
96+
while (pst->pos<pst->len&&
97+
(pst->buffer)[pst->pos]!=' ')
9798
(pst->pos)++;
9899
}
99100

100-
*tlen=pst->pos-*tlen;
101+
*tlen=pst->pos-startpos;
101102

102103
/* we are finished if (*tlen == 0) */
103104
if (*tlen==0)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp