pg_hba.conf parse error gives wrong line number

Started by Oliver Elphickabout 23 years ago3 messages
#1Oliver Elphick
olly@lfix.co.uk

With this pg_hba.conf (line numbers from vi, of course):

48 # TYPE DATABASE USER IP-ADDRESS IP-MASK METHOD 49
50 local all all ident sameuser
51 host all 127.0.0.1 127.0.0.1 ident s ameuser
52

we naturally get a parse error because of the missing user column entry
in line 51. But in the log we see:

Dec 10 19:27:42 linda postgres[10944]: [8] LOG: parse_hba: invalid
syntax in pg_hba.conf file at line 95, token "ident"

In a more complicated file, a bogus line number is going to make
debugging very tricky. I tried following this in gdb, but haven't
managed to track it through the fork of the new backend.

--
Oliver Elphick Oliver.Elphick@lfix.co.uk
Isle of Wight, UK http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"I beseech you therefore, brethren, by the mercies of
God, that ye present your bodies a living sacrifice,
holy, acceptable unto God, which is your reasonable
service." Romans 12:1

#2Bruce Momjian
pgman@candle.pha.pa.us
In reply to: Oliver Elphick (#1)
Re: pg_hba.conf parse error gives wrong line number

I see the problem with the line number here. I will work on a fix now.
Thanks.

---------------------------------------------------------------------------

Oliver Elphick wrote:

With this pg_hba.conf (line numbers from vi, of course):

48 # TYPE DATABASE USER IP-ADDRESS IP-MASK METHOD 49
50 local all all ident sameuser
51 host all 127.0.0.1 127.0.0.1 ident s ameuser
52

we naturally get a parse error because of the missing user column entry
in line 51. But in the log we see:

Dec 10 19:27:42 linda postgres[10944]: [8] LOG: parse_hba: invalid
syntax in pg_hba.conf file at line 95, token "ident"

In a more complicated file, a bogus line number is going to make
debugging very tricky. I tried following this in gdb, but haven't
managed to track it through the fork of the new backend.

--
Oliver Elphick Oliver.Elphick@lfix.co.uk
Isle of Wight, UK http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"I beseech you therefore, brethren, by the mercies of
God, that ye present your bodies a living sacrifice,
holy, acceptable unto God, which is your reasonable
service." Romans 12:1

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073
#3Bruce Momjian
pgman@candle.pha.pa.us
In reply to: Oliver Elphick (#1)
1 attachment(s)
Re: pg_hba.conf parse error gives wrong line number

OK, the following patch fixes the bug. The code wasn't handling
comments properly in dealing the the line count. I will backpatch this
into 7.3.

---------------------------------------------------------------------------

Oliver Elphick wrote:

With this pg_hba.conf (line numbers from vi, of course):

48 # TYPE DATABASE USER IP-ADDRESS IP-MASK METHOD 49
50 local all all ident sameuser
51 host all 127.0.0.1 127.0.0.1 ident s ameuser
52

we naturally get a parse error because of the missing user column entry
in line 51. But in the log we see:

Dec 10 19:27:42 linda postgres[10944]: [8] LOG: parse_hba: invalid
syntax in pg_hba.conf file at line 95, token "ident"

In a more complicated file, a bogus line number is going to make
debugging very tricky. I tried following this in gdb, but haven't
managed to track it through the fork of the new backend.

--
Oliver Elphick Oliver.Elphick@lfix.co.uk
Isle of Wight, UK http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839 932A 614D 4C34 3E1D 0C1C
========================================
"I beseech you therefore, brethren, by the mercies of
God, that ye present your bodies a living sacrifice,
holy, acceptable unto God, which is your reasonable
service." Romans 12:1

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

-- 
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

Attachments:

/bjm/difftext/plainDownload
Index: src/backend/libpq/hba.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/libpq/hba.c,v
retrieving revision 1.90
diff -c -c -r1.90 hba.c
*** src/backend/libpq/hba.c	6 Dec 2002 04:37:02 -0000	1.90
--- src/backend/libpq/hba.c	11 Dec 2002 22:13:10 -0000
***************
*** 93,98 ****
--- 93,99 ----
  next_token(FILE *fp, char *buf, const int bufsz)
  {
  	int			c;
+ 	char	   *start_buf = buf;
  	char	   *end_buf = buf + (bufsz - 1);
  	bool		in_quote = false;
  	bool		was_quote = false;
***************
*** 115,121 ****
  			{
  				while ((c = getc(fp)) != EOF && c != '\n')
  					;
! 				continue;
  			}
  
  			if (buf >= end_buf)
--- 116,125 ----
  			{
  				while ((c = getc(fp)) != EOF && c != '\n')
  					;
! 				/* If only comment, consume EOL too; return EOL */
! 				if (c != EOF && buf == start_buf)
! 					c = getc(fp);
! 				break;
  			}
  
  			if (buf >= end_buf)