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

Commit61c9ea0

Browse files
committed
Fix load_user/load_group to not leave dangling pointers around if the
config files are present on one pass and not present on a later pass.
1 parentc19354d commit61c9ea0

File tree

1 file changed

+35
-29
lines changed

1 file changed

+35
-29
lines changed

‎src/backend/libpq/hba.c

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
*
1111
*
1212
* IDENTIFICATION
13-
* $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.95 2003/03/20 03:34:55 momjian Exp $
13+
* $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.96 2003/04/03 21:25:02 tgl Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -387,7 +387,7 @@ get_group_line(const char *group)
387387
/*
388388
* Lookup a user name in the pg_shadow file
389389
*/
390-
List**
390+
List**
391391
get_user_line(constchar*user)
392392
{
393393
return (List**)bsearch((void*)user,
@@ -401,7 +401,7 @@ get_user_line(const char *user)
401401
/*
402402
* Check group for a specific user.
403403
*/
404-
staticint
404+
staticbool
405405
check_group(char*group,char*user)
406406
{
407407
List**line,
@@ -411,16 +411,16 @@ check_group(char *group, char *user)
411411
{
412412
foreach(l,lnext(lnext(*line)))
413413
if (strcmp(lfirst(l),user)==0)
414-
return1;
414+
returntrue;
415415
}
416416

417-
return0;
417+
returnfalse;
418418
}
419419

420420
/*
421421
* Check comma user list for a specific user, handle group names.
422422
*/
423-
staticint
423+
staticbool
424424
check_user(char*user,char*param_str)
425425
{
426426
char*tok;
@@ -430,42 +430,42 @@ check_user(char *user, char *param_str)
430430
if (tok[0]=='+')
431431
{
432432
if (check_group(tok+1,user))
433-
return1;
433+
returntrue;
434434
}
435435
elseif (strcmp(tok,user)==0||
436436
strcmp(tok,"all")==0)
437-
return1;
437+
returntrue;
438438
}
439439

440-
return0;
440+
returnfalse;
441441
}
442442

443443
/*
444444
* Check to see if db/user combination matches param string.
445445
*/
446-
staticint
446+
staticbool
447447
check_db(char*dbname,char*user,char*param_str)
448448
{
449449
char*tok;
450450

451451
for (tok=strtok(param_str,MULTI_VALUE_SEP);tok!=NULL;tok=strtok(NULL,MULTI_VALUE_SEP))
452452
{
453453
if (strcmp(tok,"all")==0)
454-
return1;
454+
returntrue;
455455
elseif (strcmp(tok,"sameuser")==0)
456456
{
457457
if (strcmp(dbname,user)==0)
458-
return1;
458+
returntrue;
459459
}
460460
elseif (strcmp(tok,"samegroup")==0)
461461
{
462462
if (check_group(dbname,user))
463-
return1;
463+
returntrue;
464464
}
465465
elseif (strcmp(tok,dbname)==0)
466-
return1;
466+
returntrue;
467467
}
468-
return0;
468+
returnfalse;
469469
}
470470

471471

@@ -752,13 +752,18 @@ user_openfile(void)
752752
* Load group/user name mapping file
753753
*/
754754
void
755-
load_group()
755+
load_group(void)
756756
{
757757
FILE*group_file;
758758
List*line;
759759

760+
/* Discard any old data */
760761
if (group_lines)
761762
free_lines(&group_lines);
763+
if (group_sorted)
764+
pfree(group_sorted);
765+
group_sorted=NULL;
766+
group_length=0;
762767

763768
group_file=group_openfile();
764769
if (!group_file)
@@ -767,8 +772,6 @@ load_group()
767772
FreeFile(group_file);
768773

769774
/* create sorted lines for binary searching */
770-
if (group_sorted)
771-
pfree(group_sorted);
772775
group_length=length(group_lines);
773776
if (group_length)
774777
{
@@ -779,24 +782,30 @@ load_group()
779782
foreach(line,group_lines)
780783
group_sorted[i++]=lfirst(line);
781784

782-
qsort((void*)group_sorted,group_length,sizeof(List*),user_group_qsort_cmp);
785+
qsort((void*)group_sorted,
786+
group_length,
787+
sizeof(List*),
788+
user_group_qsort_cmp);
783789
}
784-
else
785-
group_sorted=NULL;
786790
}
787791

788792

789793
/*
790794
* Load user/password mapping file
791795
*/
792796
void
793-
load_user()
797+
load_user(void)
794798
{
795799
FILE*user_file;
796800
List*line;
797801

802+
/* Discard any old data */
798803
if (user_lines)
799804
free_lines(&user_lines);
805+
if (user_sorted)
806+
pfree(user_sorted);
807+
user_sorted=NULL;
808+
user_length=0;
800809

801810
user_file=user_openfile();
802811
if (!user_file)
@@ -805,8 +814,6 @@ load_user()
805814
FreeFile(user_file);
806815

807816
/* create sorted lines for binary searching */
808-
if (user_sorted)
809-
pfree(user_sorted);
810817
user_length=length(user_lines);
811818
if (user_length)
812819
{
@@ -817,10 +824,11 @@ load_user()
817824
foreach(line,user_lines)
818825
user_sorted[i++]=lfirst(line);
819826

820-
qsort((void*)user_sorted,user_length,sizeof(List*),user_group_qsort_cmp);
827+
qsort((void*)user_sorted,
828+
user_length,
829+
sizeof(List*),
830+
user_group_qsort_cmp);
821831
}
822-
else
823-
user_sorted=NULL;
824832
}
825833

826834

@@ -848,11 +856,9 @@ load_hba(void)
848856

849857
file=AllocateFile(conf_file,"r");
850858
if (file==NULL)
851-
{
852859
elog(FATAL,
853860
"load_hba: Unable to open authentication config file \"%s\": %m",
854861
conf_file);
855-
}
856862

857863
hba_lines=tokenize_file(file);
858864
FreeFile(file);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp