psql crash fix

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: PostgreSQL-development <pgsql-hackers(at)postgreSQL(dot)org>
Subject: psql crash fix
Date: 2013-04-03 00:48:53
Message-ID: 20130403004853.GA8460@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

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(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

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

Attachment Content-Type Size
psqlrc.diff text/x-diff 2.7 KB

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Jeff Janes 2013-04-03 05:08:20 commit dfda6ebaec67 versus wal_keep_segments
Previous Message Tom Lane 2013-04-02 22:59:39 Re: spoonbill vs. -HEAD