Re: Fix for bug in ldapServiceLookup in libpq

Albe Laurenz <laurenz.albe@wien.gv.at>

From: "Albe Laurenz" <laurenz.albe@wien.gv.at>
To: "Tom Lane *EXTERN*" <tgl@sss.pgh.pa.us>
Cc: "pgsql-hackers" <pgsql-hackers@postgresql.org>
Date: 2011-05-12T08:22:23Z
Lists: pgsql-hackers

Attachments

Tom Lane wrote:
>> I have found a small but annoying bug in libpq where
>> connection parameters are resolved via LDAP.

> Hmm ... that's a bug all right, but why have the null-termination
> inside the loop at all?  Seems like it should look like
>
>	for (p = result, i = 0; values[i] != NULL; ++i)
>	{
>		strncpy(p, values[i]->bv_val, values[i]->bv_len);
>		p += values[i]->bv_len;
>		*(p++) = '\n';
>	}
>	*p = '\0';

Yes, that's better.

> ... btw, shouldn't this function free the "result" string when it's
done
> with it?  AFAICS that string is not returned to the caller, it's just
> being leaked.

Oops, yes it should.

> (I'll refrain from asking why it's creating the string in the first
> place rather than parsing ldap_get_values_len's output as-is ...)

So that I can close the LDAP connection as soon as feasible, but of
course
that's not absolutely necessary.

I have attached a new version of the patch that should address all known
problems.

Yours,
Laurenz Albe