[BUG/PATCH] backend crashes during authentication if data/global/pg_pwd is empty

Поиск
Список
Период
Сортировка
От Michael Wildpaner
Тема [BUG/PATCH] backend crashes during authentication if data/global/pg_pwd is empty
Дата
Msg-id Pine.LNX.4.58.0312051343500.30242@rainbow.studorg.tuwien.ac.at
обсуждение исходный текст
Ответы Re: [BUG/PATCH] backend crashes during authentication if data/global/pg_pwd is empty  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-hackers
Hi,

on Solaris 9 with PostgreSQL 7.4:

when you
 - 'initdb' a fresh database, - _don't_ set a password for user 'postgres', - convert the 'trust' lines in
data/pg_hba.confto 'md5' or 'password'
 

and then try to connect as user 'postgres', the backend crashes in
backend/libpq/hba.c:372:
   368 static int   369 user_group_bsearch_cmp(const void *user, const void *list)   370 {   371         /* first node
isline number */   372         char       *user2 = lfirst(lnext(*(List **) list));
 

due to 'list' being NULL, which might mean that 'user_sorted' was never
allocated, due to user_length being zero for an missing or empty
global/pg_pwd:
   916         /* create sorted lines for binary searching */   917         user_length = length(user_lines);   918
   if (user_length)   919         {   920                 int                     i = 0;   921   922
user_sorted= palloc(user_length * sizeof(List *));
 

I know this is looks like a case of "don't do it, then", but since it's a
backend crash, I would suggest the following fix:

--- postgresql-7.4.orig/src/backend/libpq/hba.c    2003-10-25 05:48:46.000001000 +0200
+++ postgresql-7.4/src/backend/libpq/hba.c    2003-12-05 15:21:54.000003000 +0100
@@ -62,7 +62,7 @@static List **user_sorted = NULL;        /* sorted user list, for bsearch() */static List
**group_sorted= NULL;        /* sorted group list, for                                         * bsearch() */
 
-static int    user_length;
+static int    user_length = 0;static int    group_length;
static List *tokenize_file(FILE *file);
@@ -395,6 +395,10 @@List      **get_user_line(const char *user){
+    /* fail if there is nothing to search in */
+    if ((user_sorted == NULL) || (user_length == 0))
+        return NULL;
+    return (List **) bsearch((void *) user,                             (void *) user_sorted,
  user_length,
 

The initialization of user_length might not be necessary.

Best wishes, Mike

PS: This might be related to   http://archives.postgresql.org/pgsql-admin/2003-03/msg00413.php

-- 
Life is like a fire.                            DI Michael Wildpaner
Flames which the passer-by forgets.                    Ph.D. Student
Ashes which the wind scatters.
A man lived.       -- Omar Khayyam


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Pavel Stehule
Дата:
Сообщение: why I need col. def. list with setof record?
Следующее
От: Tom Lane
Дата:
Сообщение: Re: [BUG/PATCH] backend crashes during authentication if data/global/pg_pwd is empty