Re: Patch for 1-byte buffer overflow in libpq PQencryptPassword - Mailing list pgsql-hackers

From Tom Lane
Subject Re: Patch for 1-byte buffer overflow in libpq PQencryptPassword
Date
Msg-id 23416.1252975461@sss.pgh.pa.us
Whole thread Raw
In response to Patch for 1-byte buffer overflow in libpq PQencryptPassword  (ljb <ljb1813@pobox.com>)
List pgsql-hackers
ljb <ljb1813@pobox.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


pgsql-hackers by date:

Previous
From: Andrew Dunstan
Date:
Subject: Re: Feature Request: JSON input for hstore
Next
From: Robert Haas
Date:
Subject: CommitFest 2009-09: Now In Progress