Re: Fix for bug in ldapServiceLookup in libpq

Tom Lane <tgl@sss.pgh.pa.us>

From: Tom Lane <tgl@sss.pgh.pa.us>
To: "Albe Laurenz" <laurenz.albe@wien.gv.at>
Cc: "pgsql-hackers" <pgsql-hackers@postgresql.org>
Date: 2011-05-11T16:00:46Z
Lists: pgsql-hackers
"Albe Laurenz" <laurenz.albe@wien.gv.at> writes:
> I have found a small but annoying bug in libpq where
> connection parameters are resolved via LDAP.

> There is a write past the end of a malloc'ed string which causes
> memory corruption. The code and the bug are originally by me :^(

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';

> This should be backpatched to 8.2 where the code was introduced.

Yes, will do.

			regards, tom lane