psql crash fix

Started by Bruce Momjianabout 13 years ago2 messageshackers
Jump to latest
#1Bruce Momjian
bruce@momjian.us

I found that psql will crash if given a PSQLRC value containing a tilde:

$ PSQLRC="~/x" psql test
*** glibc detected *** psql: free(): invalid pointer: 0x00007fffb7c933ec ***

This is on Debian Squeeze 6.0.7. The fix is to pstrdup() the value
returned by getenv(), so it can be free()'ed later --- you can't free
getenv()-returned values:

As typically implemented, getenv() returns a pointer to a string
within the environment list. The caller must take care not to
modify this string, since that would change the environment of
the process.

This bug exists in 9.2 and git head. I also removed the return value
from expand_tilde() as no caller was using it.

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

Attachments:

psqlrc.difftext/x-diff; charset=us-asciiDownload+17-19
#2Bruce Momjian
bruce@momjian.us
In reply to: Bruce Momjian (#1)
Re: psql crash fix

On Tue, Apr 2, 2013 at 08:48:53PM -0400, Bruce Momjian wrote:

I found that psql will crash if given a PSQLRC value containing a tilde:

$ PSQLRC="~/x" psql test
*** glibc detected *** psql: free(): invalid pointer: 0x00007fffb7c933ec ***

This is on Debian Squeeze 6.0.7. The fix is to pstrdup() the value
returned by getenv(), so it can be free()'ed later --- you can't free
getenv()-returned values:

As typically implemented, getenv() returns a pointer to a string
within the environment list. The caller must take care not to
modify this string, since that would change the environment of
the process.

This bug exists in 9.2 and git head. I also removed the return value
from expand_tilde() as no caller was using it.

Applied.

--
Bruce Momjian <bruce@momjian.us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ It's impossible for everything to be true. +

--
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers