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

Commit040f28b

Browse files
committed
Fix pg_ctl's readfile() to not go into infinite loop on an empty file
(could happen if either postgresql.conf or postmaster.opts is empty).It's been broken since the C version was written for 8.0, so patchall the way back.initdb's copy of the function is broken in the same way, but it'sless important there since the input files should never be empty.Patch that in HEAD only, and also fix some cosmetic differences thatcrept into that copy of the function.Per report from Corry Haines and Jeff Davis.
1 parent794e3e8 commit040f28b

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

‎src/bin/initdb/initdb.c

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
* Portions Copyright (c) 1994, Regents of the University of California
4343
* Portions taken from FreeBSD.
4444
*
45-
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.173 2009/09/01 02:54:52alvherre Exp $
45+
* $PostgreSQL: pgsql/src/bin/initdb/initdb.c,v 1.174 2009/09/02 02:40:52tgl Exp $
4646
*
4747
*-------------------------------------------------------------------------
4848
*/
@@ -149,7 +149,7 @@ static char **replace_token(char **lines,
149149
#ifndefHAVE_UNIX_SOCKETS
150150
staticchar**filter_lines_with_token(char**lines,constchar*token);
151151
#endif
152-
staticchar**readfile(char*path);
152+
staticchar**readfile(constchar*path);
153153
staticvoidwritefile(char*path,char**lines);
154154
staticFILE*popen_check(constchar*command,constchar*mode);
155155
staticintmkdir_p(char*path,mode_tomode);
@@ -362,10 +362,10 @@ filter_lines_with_token(char **lines, const char *token)
362362
* get the lines from a text file
363363
*/
364364
staticchar**
365-
readfile(char*path)
365+
readfile(constchar*path)
366366
{
367367
FILE*infile;
368-
intmaxlength=0,
368+
intmaxlength=1,
369369
linelen=0;
370370
intnlines=0;
371371
char**result;
@@ -394,26 +394,20 @@ readfile(char *path)
394394
}
395395

396396
/* handle last line without a terminating newline (yuck) */
397-
398397
if (linelen)
399398
nlines++;
400399
if (linelen>maxlength)
401400
maxlength=linelen;
402401

403402
/* set up the result and the line buffer */
404-
405-
result= (char**)pg_malloc((nlines+2)*sizeof(char*));
406-
buffer= (char*)pg_malloc(maxlength+2);
403+
result= (char**)pg_malloc((nlines+1)*sizeof(char*));
404+
buffer= (char*)pg_malloc(maxlength+1);
407405

408406
/* now reprocess the file and store the lines */
409-
410407
rewind(infile);
411408
nlines=0;
412409
while (fgets(buffer,maxlength+1,infile)!=NULL)
413-
{
414-
result[nlines]=xstrdup(buffer);
415-
nlines++;
416-
}
410+
result[nlines++]=xstrdup(buffer);
417411

418412
fclose(infile);
419413
free(buffer);

‎src/bin/pg_ctl/pg_ctl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
66
*
7-
* $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.112 2009/08/27 16:59:38 tgl Exp $
7+
* $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.113 2009/09/02 02:40:52 tgl Exp $
88
*
99
*-------------------------------------------------------------------------
1010
*/
@@ -292,7 +292,7 @@ static char **
292292
readfile(constchar*path)
293293
{
294294
FILE*infile;
295-
intmaxlength=0,
295+
intmaxlength=1,
296296
linelen=0;
297297
intnlines=0;
298298
char**result;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp