Re: BUG #14859: Config file parsing is allergic to spaces on last line of file

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: boatcoder(at)gmail(dot)com, "pgsql-bugs(at)postgresql(dot)org" <pgsql-bugs(at)postgresql(dot)org>
Subject: Re: BUG #14859: Config file parsing is allergic to spaces on last line of file
Date: 2017-10-17 15:28:29
Message-ID: 17375.1508254109@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

"David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> On Tue, Oct 17, 2017 at 7:44 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> Hmph. I can reproduce this in 9.6 and earlier, but not in v10 or HEAD.
>> Apparently somebody fixed it by accident. Looking ...

> ​Probably as a side-effect of:
> "​Add view pg_hba_file_rules to display the contents of pg_hba.conf"
> to v10 (you can probably find the commit hash faster than I).

Close, but apparently it was the adjacent commit 1e5a5d03d,
"Simplify some long-obsolete code in hba.c's next_token()."
in which I wrote

Also, ensure that we don't return with *lineptr set to someplace past the
terminating '\0'; that would be catastrophic if a caller were to ask for
another token from the same line. This is just latent since no callers
actually do call again after a "false" return; but considering that it was
actually costing us extra code to do it wrong, we might as well make it
bulletproof.

I was wrong to think that the problem was only latent, because
tokenize_file() decides whether there's more on the line using

while (strlen(lineptr) > 0)

so that having advanced lineptr past the current line's '\0' allows
it to see (and process) whatever had been in the buffer beyond that
from preceding line(s).

This seems to have been broken since 9.3; kinda surprising nobody
noticed earlier. I shall go back-patch 1e5a5d03d --- it does a bit
more than the minimum needed to fix the bug, but the other changes
seem harmless enough.

regards, tom lane

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Eric Joniec 2017-10-17 16:51:23 pgbouncer-1.7.2-7.rhel6.x86_64.rpm fails to install on AMI
Previous Message David G. Johnston 2017-10-17 14:58:05 Re: BUG #14859: Config file parsing is allergic to spaces on last line of file