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

Commitedcaa8f

Browse files
committed
Fix off-by-one memory allocation, as reported by Rod Taylor. Also
avoid repalloc'ing twice when once is sufficient.
1 parent6444bc3 commitedcaa8f

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

‎src/backend/libpq/hba.c

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/backend/libpq/hba.c,v 1.133 2004/10/12 21:54:38 petere Exp $
13+
* $PostgreSQL: pgsql/src/backend/libpq/hba.c,v 1.134 2004/11/17 19:54:24 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -218,6 +218,7 @@ next_token_expand(FILE *file)
218218
char*comma_str=pstrdup("");
219219
booltrailing_comma;
220220
char*incbuf;
221+
intneeded;
221222

222223
do
223224
{
@@ -239,16 +240,14 @@ next_token_expand(FILE *file)
239240
else
240241
incbuf=pstrdup(buf);
241242

242-
comma_str=repalloc(comma_str,
243-
strlen(comma_str)+strlen(incbuf)+1);
243+
needed=strlen(comma_str)+strlen(incbuf)+1;
244+
if (trailing_comma)
245+
needed++;
246+
comma_str=repalloc(comma_str,needed);
244247
strcat(comma_str,incbuf);
245-
pfree(incbuf);
246-
247248
if (trailing_comma)
248-
{
249-
comma_str=repalloc(comma_str,strlen(comma_str)+1+1);
250249
strcat(comma_str,MULTI_VALUE_SEP);
251-
}
250+
pfree(incbuf);
252251
}while (trailing_comma);
253252

254253
returncomma_str;
@@ -327,29 +326,31 @@ tokenize_inc_file(const char *inc_filename)
327326
pfree(inc_fullname);
328327

329328
/* return empty string, it matches nothing */
330-
returnpstrdup("");
329+
returncomma_str;
331330
}
332331
pfree(inc_fullname);
333332

334333
/* There is possible recursion here if the file contains @ */
335334
tokenize_file(inc_file,&inc_lines,&inc_line_nums);
336335
FreeFile(inc_file);
337336

338-
/* Create comma-separate string from List */
337+
/* Create comma-separated string from List */
339338
foreach(line,inc_lines)
340339
{
341340
List*token_list= (List*)lfirst(line);
342341
ListCell*token;
343342

344343
foreach(token,token_list)
345344
{
346-
if (strlen(comma_str))
347-
{
348-
comma_str=repalloc(comma_str,strlen(comma_str)+1);
345+
intoldlen=strlen(comma_str);
346+
intneeded;
347+
348+
needed=oldlen+strlen(lfirst(token))+1;
349+
if (oldlen>0)
350+
needed++;
351+
comma_str=repalloc(comma_str,needed);
352+
if (oldlen>0)
349353
strcat(comma_str,MULTI_VALUE_SEP);
350-
}
351-
comma_str=repalloc(comma_str,
352-
strlen(comma_str)+strlen(lfirst(token))+1);
353354
strcat(comma_str,lfirst(token));
354355
}
355356
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp