Re: [PATCH] pgcrypto: Fix sha-crypt rounds= values that do not fit in int (BUG #19743)

From: Chao Li <li(dot)evan(dot)chao(at)gmail(dot)com>
To: Prashant Chinnam <crprashant(at)hotmail(dot)com>
Cc: Takeshi Ideriha <iderihatakeshi(at)gmail(dot)com>, "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: [PATCH] pgcrypto: Fix sha-crypt rounds= values that do not fit in int (BUG #19743)
Date: 2026-10-27 06:01:32
Message-ID: 852FF0DD-8C49-4A7A-8CE1-C7421F1E97B7@gmail.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> On Oct 27, 2026, at 09:13, Prashant Chinnam <crprashant(at)hotmail(dot)com> wrote:
>
> Hi Takeshi,
>
> Thanks again for the review and the alternative patch.
> Attached is v2, which adopts your strtoi64 approach as
> discussed.
>
> The crypt-sha.c change is the one you suggested: parse rounds=
> with strtoi64() so out-of-range values saturate into the
> existing clamping, and report the value as supplied in the
> clamp NOTICEs. The regression tests are carried over from v1
> unchanged.
>
> Behaviour is identical to v1 on the full test battery,
> including the values beyond int64 in both directions, and the
> pgcrypto regression suite passes 25/25.
>
> As noted before, sha-crypt support exists only in PG 18 and
> master, so backpatching to REL_18_STABLE should be considered.
>
> Testing was done with AI assistance.
>
> Regards,
> Prashant Chinnam<v2-0001-pgcrypto-Fix-sha-crypt-rounds-values-that-do-not-fit.patch>

I think strtoi64() works properly here. It maps to strtol() or strtoll(), depending on the platform. According to the man page [1], on overflow, it returns INT64_MAX or INT64_MIN. Both values are outside the supported range (PX_SHACRYPT_ROUNDS_MIN, PX_SHACRYPT_ROUNDS_MAX), so srounds will be clamped correctly.

Another thing the patch does is change the NOTICE message to print the original input string, which is good in most cases. A small concern is: what if the input string is unreasonably long? Maybe we should cap the maximum length of the printed string?

[1] https://man7.org/linux/man-pages/man3/strtol.3p.html

Best regards,
--
Chao Li (Evan)
HighGo Software Co., Ltd.
https://www.highgo.com/

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Chao Li 2026-10-27 06:15:37 Re: Event trigger table rewrite doc missing ALTER MATERIALIZED VIEW case
Previous Message Jeremy Schneider 2026-10-27 05:58:28 Re: Skip prefetch for block references that follow a FPW or WILL_INIT of the same block