Re: usermap regexp support

From: Magnus Hagander <magnus(at)hagander(dot)net>
To: Gianni Ciolli <gianni(dot)ciolli(at)2ndquadrant(dot)it>
Cc: PG Hackers <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: usermap regexp support
Date: 2008-11-11 13:59:01
Message-ID: 49198FA5.6020206@hagander.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Gianni Ciolli wrote:
> On Tue, Oct 28, 2008 at 08:59:53PM +0100, Magnus Hagander wrote:
>> The attached patch tries to implement regexp support in the usermaps
>> (pg_ident.conf).
>
> Hi Magnus,
>
> I am currently reviewing your patch.

Hi!

Thanks for the review!

> I found out that the execution of
>
> pfree(regexp_pgrole);
>
> (there's only one such line in your patch) might raise on the current
> HEAD the following message
>
> WARNING: detected write past chunk end in Postmaster 0x9b13650

Yes, that's a stupid bug:
- /* length: original length minus length of \1
plus length of match */
- regexp_pgrole =
palloc0(strlen(file_pgrole)-2+(matches[1].rm_so-matches[1].rm_so));
+ /* length: original length minus length of \1
plus length of match plus null terminator */
+ regexp_pgrole = palloc0(strlen(file_pgrole) - 2
+ (matches[1].rm_eo-matches[1].rm_so) + 1);

Two bugs: the length calculation used the start of the string vs the
start of the string, instead of end vs start. And there was no room for
the NULL terminator.

Attached is an updated version of the patch that fixes this.

//Magnus

Attachment Content-Type Size
ident_regexp.patch text/x-diff 4.5 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Sergey Konoplev 2008-11-11 14:03:44 Re: Very slow queries w/ NOT IN preparation (seems like a bug, test case)
Previous Message Alvaro Herrera 2008-11-11 13:44:12 Re: Duplicated docs on libpq parameters