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

Commit7454515

Browse files
committed
Fix mistakes in pg_ctl's code for "start -w" that tries to cope with
non-default settings for the postmaster's port number. The code to parsecommand line options and postgresql.conf entries wasn't quite right aboutwhitespace or quotes, and it was coded in a not-very-readable way too.Per bug #3969 from Itagaki Takahiro, though this is more extensive than hisproposed patch (which fixed only the whitespace problem).This code has been broken since it was put in in 8.0, so patch all the wayback.
1 parent5ce6829 commit7454515

File tree

1 file changed

+43
-19
lines changed

1 file changed

+43
-19
lines changed

‎src/bin/pg_ctl/pg_ctl.c

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
66
*
7-
* $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.92 2008/01/01 19:45:55 momjian Exp $
7+
* $PostgreSQL: pgsql/src/bin/pg_ctl/pg_ctl.c,v 1.93 2008/02/20 22:18:15 tgl Exp $
88
*
99
*-------------------------------------------------------------------------
1010
*/
@@ -49,8 +49,6 @@ intoptreset;
4949
typedeflongpgpid_t;
5050

5151

52-
#defineWHITESPACE "\f\n\r\t\v"/* as defined by isspace() */
53-
5452
/* postgres version ident string */
5553
#definePM_VERSIONSTR "postgres (PostgreSQL) " PG_VERSION "\n"
5654

@@ -416,33 +414,52 @@ test_postmaster_connection(bool do_checkpoint)
416414
inti;
417415
charportstr[32];
418416
char*p;
417+
char*q;
419418
charconnstr[128];/* Should be way more than enough! */
420419

421420
*portstr='\0';
422421

423-
/* post_opts */
422+
/*
423+
* Look in post_opts for a -p switch.
424+
*
425+
* This parsing code is not amazingly bright; it could for instance
426+
* get fooled if ' -p' occurs within a quoted argument value. Given
427+
* that few people pass complicated settings in post_opts, it's
428+
* probably good enough.
429+
*/
424430
for (p=post_opts;*p;)
425431
{
426-
/* advance past whitespace/quoting */
427-
while (isspace((unsignedchar)*p)||*p=='\''||*p=='"')
432+
/* advance past whitespace */
433+
while (isspace((unsignedchar)*p))
428434
p++;
429435

430-
if (strncmp(p,"-p",strlen("-p"))==0)
436+
if (strncmp(p,"-p",2)==0)
431437
{
432-
p+=strlen("-p");
433-
/* advance past whitespace/quoting */
438+
p+=2;
439+
/* advance pastanywhitespace/quoting */
434440
while (isspace((unsignedchar)*p)||*p=='\''||*p=='"')
435441
p++;
436-
strlcpy(portstr,p,Min(strcspn(p,"\"'"WHITESPACE)+1,
437-
sizeof(portstr)));
442+
/* find end of value (not including any ending quote!) */
443+
q=p;
444+
while (*q&&
445+
!(isspace((unsignedchar)*q)||*q=='\''||*q=='"'))
446+
q++;
447+
/* and save the argument value */
448+
strlcpy(portstr,p,Min((q-p)+1,sizeof(portstr)));
438449
/* keep looking, maybe there is another -p */
450+
p=q;
439451
}
440452
/* Advance to next whitespace */
441453
while (*p&& !isspace((unsignedchar)*p))
442454
p++;
443455
}
444456

445-
/* config file */
457+
/*
458+
* Search config file for a 'port' option.
459+
*
460+
* This parsing code isn't amazingly bright either, but it should be
461+
* okay for valid port settings.
462+
*/
446463
if (!*portstr)
447464
{
448465
char**optlines;
@@ -456,28 +473,35 @@ test_postmaster_connection(bool do_checkpoint)
456473

457474
while (isspace((unsignedchar)*p))
458475
p++;
459-
if (strncmp(p,"port",strlen("port"))!=0)
476+
if (strncmp(p,"port",4)!=0)
460477
continue;
461-
p+=strlen("port");
478+
p+=4;
462479
while (isspace((unsignedchar)*p))
463480
p++;
464481
if (*p!='=')
465482
continue;
466483
p++;
467-
while (isspace((unsignedchar)*p))
484+
/* advance past any whitespace/quoting */
485+
while (isspace((unsignedchar)*p)||*p=='\''||*p=='"')
468486
p++;
469-
strlcpy(portstr,p,Min(strcspn(p,"#"WHITESPACE)+1,
470-
sizeof(portstr)));
487+
/* find end of value (not including any ending quote/comment!) */
488+
q=p;
489+
while (*q&&
490+
!(isspace((unsignedchar)*q)||
491+
*q=='\''||*q=='"'||*q=='#'))
492+
q++;
493+
/* and save the argument value */
494+
strlcpy(portstr,p,Min((q-p)+1,sizeof(portstr)));
471495
/* keep looking, maybe there is another */
472496
}
473497
}
474498
}
475499

476-
/* environment */
500+
/*Checkenvironment */
477501
if (!*portstr&&getenv("PGPORT")!=NULL)
478502
strlcpy(portstr,getenv("PGPORT"),sizeof(portstr));
479503

480-
/* default */
504+
/*Else use compiled-indefault */
481505
if (!*portstr)
482506
snprintf(portstr,sizeof(portstr),"%d",DEF_PGPORT);
483507

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp