psql history vs. dearmor (pgcrypto)
Hi,
I've noticed that psql query buffer somehow interferes with dearmor
(from pgcrypto), corrupting the data. For example this works fine:
SELECT dearmor('-----BEGIN PGP PUBLIC KEY BLOCK-----
Version: GnuPG v2.0.17 (GNU/Linux)
mQGiBE7AfUoRBACpupjE5tG9Fh1dWe2kb/yX+lNlMLpwMj1hjTrJo1cYmSYixkGX
Si90ZIjn0IOSU7XOkFai8btpbFGyGSdaB9BQK7s8ItN/wx9IHcnB83Lbex3aF/VS
hN81VummzKQ0YB+Crwp1mu1l76UrTg6sPnY+wHj3jPOleXcX9L9UAAzOnwCgi4OS
JoRzR/pPiWtW0Nk5qnYhuZMD/RyNYbKkoNVO4WUnfOFMqm2zIqRXmMnkXS6gNPsd
RNVXb4ByFSzugsZKW5ez9+zS0G0aarySQIuGgPGKSeZezYtwKR3DH676MmdnNSvx
GiGDQW+hSXBOiBOmxhZfBK8H6JfmEtUpZwA8tkzD0u6ikZjQZR0cRux/tdutzTuZ
YGyaA/4tWzKtQP+WDi5tUPNO1/7EcBphYMvZDfNzYUn5ZwXzw5B5YSi0rdY6ZLSP
H3X8hrHbSmDrD8KseLtl9E4YvaOWd0BZCg9QwUcVrR+9sYtyNy/ztX++vVOtFjQ6
b19rj0853fwSgv9gHoNelmBXs0jTDGaKSBwzTD8GYtusQcu3lbQZYWFhYWEgPGFh
YWFhQGV4YW1wbGUuY29tPohiBBMRAgAiBQJOwH1KAhsDBgsJCAcDAgYVCAIJCgsE
FgIDAQIeAQIXgAAKCRCNcpg0BUjyDOKPAJ4viutaojyBhV0ICJED09ArUXgZ7ACf
U6CX156L6i6x8UzRLFxsvVKHXIK5AQ0ETsB9ShAEAMDqwXmBeJGqWgXrtVKh6XIw
uanQtl/lIhktVcAYa/FHnvleL9RqI6JpiVWuvLfOdDcUQmh3MvsmD6h6plVmg/bz
/y1ZGnWANjCazmSWDjTfuIX+wuWo4TKSRhXzUd5tw5bgaeC0Hvy+rlgswRILFYL1
5I0/NTm+fFkB0McY9E2fAAMHBACgpmaAW/VR4IGn+j74GCzn2W06UnnWSK7A0GPJ
kUiJa37mv04yCeIqmoTVkl5rnz8dZZUwJVKYwlRvvLB/omIdzRkouhK/QWioRQ+M
B5qPXjRNrcUnruWVzC3XfhZ6sImI8bh2tHpN1/r0hHXFb/5078Bv2d4Cq2WdMZJo
oGDxBIhJBBgRAgAJBQJOwH1KAhsMAAoJEI1ymDQFSPIM7RcAn22lbnWNWiGby9SU
mEQSkrE34O8+AKCFFPLQiCs3/EL3+2DsplWOnEcSuQ==
=Q6Oq
-----END PGP PUBLIC KEY BLOCK-----');
but recalling it from the query buffer results in
ERROR: Corrupt ascii-armor
I've noticed this on 9.1 but 9.2devel behaves exactly the same. I'm
using 64-bit Linux with UTF8, nothing special.
Tomas
2011/11/13 Tomas Vondra <tv@fuzzy.cz>:
but recalling it from the query buffer results in
ERROR: Corrupt ascii-armor
I've noticed this on 9.1 but 9.2devel behaves exactly the same. I'm
using 64-bit Linux with UTF8, nothing special.
It looks like the problem is that the original has a blank line after
the line that says "Version: GnuPG v2.0.17 (GNU/Linux)", but when you
recall it from the query buffer, that extra blank line gets elided.
The attached patch fixes it for me. I'm a little worried it might
cause a problem in some case I'm not thinking about, but I can't think
of any such case right this minute.
--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise PostgreSQL Company
Attachments:
save-empty-lines.patchapplication/octet-stream; name=save-empty-lines.patchDownload
diff --git a/src/bin/psql/input.c b/src/bin/psql/input.c
index 6628c0c..ec0e6e1 100644
--- a/src/bin/psql/input.c
+++ b/src/bin/psql/input.c
@@ -95,10 +95,10 @@ void
pg_append_history(const char *s, PQExpBuffer history_buf)
{
#ifdef USE_READLINE
- if (useHistory && s && s[0])
+ if (useHistory && s)
{
appendPQExpBufferStr(history_buf, s);
- if (s[strlen(s) - 1] != '\n')
+ if (!s[0] || s[strlen(s) - 1] != '\n')
appendPQExpBufferChar(history_buf, '\n');
}
#endif