Re: BUG #19714: pgcrypto pgp_sym_encrypt accepts nonnumeric s2k-mode as mode 0

From: shihao zhong <zhong950419(at)gmail(dot)com>
To: imchifan(at)163(dot)com, pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Re: BUG #19714: pgcrypto pgp_sym_encrypt accepts nonnumeric s2k-mode as mode 0
Date: 2026-09-25 04:37:21
Message-ID: CAGRkXqR5G=Z1U5-EE_LGqa9TGP082sJiBZM4JR39crbrzVZbXw@mail.gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hi

All the integer PGP options are parsed with atoi(), so trailing junk
("s2k-mode=3x") and values that wrap around int ("s2k-mode=4294967299"
gives 3) get through too.

This is not a common case. It only happens when the caller writes a bad
option string, and *the caller could ask for mode 0 directly anyway,* so
it is not a security problem. The one case worth fixing is s2k-mode.
Junk there gives the unsalted mode 0, and decryption still works, so
nobody would notice. "s2k-mode=salted" is an easy mistake to make,
since the other S2K options take names.

0001 parses the values with strtoint() and raises the existing "Illegal
argument to function" error. 0002 adds tests and is optional.

This makes some inputs that work today fail, so I'd keep it to master.
I can do back-branch versions if a committer wants it back-patched.

Shihao

Attachment Content-Type Size
v1-0002-pgcrypto-Add-tests-for-malformed-integer-PGP-opti.patch application/octet-stream 3.0 KB
v1-0001-pgcrypto-Reject-malformed-integer-values-in-PGP-o.patch application/octet-stream 4.9 KB

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message shihao zhong 2026-09-25 04:59:59 Re: BUG #19699: LIKE with a trailing escape fails to raise SQLSTATE 22025 for empty input
Previous Message shihao zhong 2026-09-25 04:29:41 Re: BUG #19705: One NaN box makes a BRIN box_inclusion_ops index omit unrelated rows