if salt_len == 0. This seems to be mostly academic, since nearly all calling
code paths guarantee nonempty salt; the only case that doesn't is
PQencryptPassword where the caller could mistakenly pass an empty username.
So, fix it but don't bother backpatching. Per ljb.
char *buf)
{
size_t passwd_len = strlen(passwd);
- char *crypt_buf = malloc(passwd_len + salt_len);
+ /* +1 here is just to avoid risk of unportable malloc(0) */
+ char *crypt_buf = malloc(passwd_len + salt_len + 1);
bool ret;
if (!crypt_buf)
* Place salt at the end because it may be known by users trying to crack
* the MD5 output.
*/
- strcpy(crypt_buf, passwd);
+ memcpy(crypt_buf, passwd, passwd_len);
memcpy(crypt_buf + passwd_len, salt, salt_len);
strcpy(buf, "md5");