Re: Patch for 1-byte buffer overflow in libpq PQencryptPassword

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: ljb <ljb1813(at)pobox(dot)com>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Patch for 1-byte buffer overflow in libpq PQencryptPassword
Date: 2009-09-15 00:44:21
Message-ID: 23416.1252975461@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

ljb <ljb1813(at)pobox(dot)com> writes:
> Two possible suggested fixes to src/backend/libpq/md5.c, pg_md5_crypt():
> 1) Allocate crypt_buf to (passwd_len + 1 + salt_len)
> 2) Use memcpy(crypt_buf, passwd, passwd_len) not strcpy(crypt_buf, passwd).

> I like fix #2 better, although fix #1 avoids a weirdness with
> PQencryptPassword("","") calling malloc(0) with platform-dependent
> results (which was the problem I was chasing with pgtclng).

Hmm ... I'm inclined to do both. I agree that the memcpy coding is
cleaner than strcpy when we don't actually care about adding a trailing
null. But malloc(0) is unportable and best avoided.

regards, tom lane

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2009-09-15 01:14:02 CommitFest 2009-09: Now In Progress
Previous Message Andrew Dunstan 2009-09-15 00:35:23 Re: Feature Request: JSON input for hstore