From 4d01289a53adea3b6c980e6a4b2328dd09e29e3b Mon Sep 17 00:00:00 2001 From: Shihao Date: Thu, 24 Sep 2026 23:58:52 -0400 Subject: [PATCH v1 2/2] pgcrypto: Add tests for malformed integer PGP option values. Check that a non-numeric value, trailing junk and an out of range value are rejected. Without the parser fix, all three are silently accepted and "s2k-mode=not_a_number" encrypts with S2K mode 0. Discussion: https://postgr.es/m/19714-2c7439b39f73bde9@postgresql.org --- contrib/pgcrypto/expected/pgp-encrypt.out | 7 +++++++ contrib/pgcrypto/expected/pgp-encrypt_1.out | 7 +++++++ contrib/pgcrypto/sql/pgp-encrypt.sql | 5 +++++ 3 files changed, 19 insertions(+) diff --git a/contrib/pgcrypto/expected/pgp-encrypt.out b/contrib/pgcrypto/expected/pgp-encrypt.out index 50cd3f6daa0..a6ca7334079 100644 --- a/contrib/pgcrypto/expected/pgp-encrypt.out +++ b/contrib/pgcrypto/expected/pgp-encrypt.out @@ -120,6 +120,13 @@ NOTICE: pgp_decrypt: unexpected s2k_count: expected 65000000 got 65011712 Secret. (1 row) +-- integer options must be valid integers +select pgp_sym_encrypt('Secret.', 'key', 's2k-mode=not_a_number'); +ERROR: Illegal argument to function +select pgp_sym_encrypt('Secret.', 'key', 's2k-mode=3x'); +ERROR: Illegal argument to function +select pgp_sym_encrypt('Secret.', 'key', 's2k-count=4294968320'); +ERROR: Illegal argument to function -- s2k digest change select pgp_sym_decrypt( pgp_sym_encrypt('Secret.', 'key', 's2k-digest-algo=sha1'), diff --git a/contrib/pgcrypto/expected/pgp-encrypt_1.out b/contrib/pgcrypto/expected/pgp-encrypt_1.out index 36b1052809c..e828300f415 100644 --- a/contrib/pgcrypto/expected/pgp-encrypt_1.out +++ b/contrib/pgcrypto/expected/pgp-encrypt_1.out @@ -116,6 +116,13 @@ NOTICE: pgp_decrypt: unexpected s2k_count: expected 65000000 got 65011712 Secret. (1 row) +-- integer options must be valid integers +select pgp_sym_encrypt('Secret.', 'key', 's2k-mode=not_a_number'); +ERROR: Illegal argument to function +select pgp_sym_encrypt('Secret.', 'key', 's2k-mode=3x'); +ERROR: Illegal argument to function +select pgp_sym_encrypt('Secret.', 'key', 's2k-count=4294968320'); +ERROR: Illegal argument to function -- s2k digest change select pgp_sym_decrypt( pgp_sym_encrypt('Secret.', 'key', 's2k-digest-algo=sha1'), diff --git a/contrib/pgcrypto/sql/pgp-encrypt.sql b/contrib/pgcrypto/sql/pgp-encrypt.sql index f67329c2c30..e806f5761af 100644 --- a/contrib/pgcrypto/sql/pgp-encrypt.sql +++ b/contrib/pgcrypto/sql/pgp-encrypt.sql @@ -62,6 +62,11 @@ select pgp_sym_decrypt( pgp_sym_encrypt('Secret.', 'key', 's2k-count=65000000'), 'key', 'expect-s2k-count=65000000'); +-- integer options must be valid integers +select pgp_sym_encrypt('Secret.', 'key', 's2k-mode=not_a_number'); +select pgp_sym_encrypt('Secret.', 'key', 's2k-mode=3x'); +select pgp_sym_encrypt('Secret.', 'key', 's2k-count=4294968320'); + -- s2k digest change select pgp_sym_decrypt( pgp_sym_encrypt('Secret.', 'key', 's2k-digest-algo=sha1'), -- 2.37.1 (Apple Git-137.1)