pgsql: libpq-oauth: Avoid overflow for very large intervals

From: Jacob Champion <jchampion(at)postgresql(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: libpq-oauth: Avoid overflow for very large intervals
Date: 2026-07-31 18:27:10
Message-ID: E1wprws-0000000182n-1xrv@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

libpq-oauth: Avoid overflow for very large intervals

The slow_down interval parsing code checks explicitly for overflow, but
since it does that after the signed overflow has already occurred, we
end up inviting undefined behavior from the compiler anyway.

Use checked arithmetic instead. set_timer() takes a long int in order to
interface nicely with libcurl, so use an int32 as the interval counter
and clamp to LONG_MAX during conversion to milliseconds.

Backpatch to 18, where libpq-oauth was introduced.

Reported-by: Andres Freund <andres(at)anarazel(dot)de>
Reviewed-by: Daniel Gustafsson <daniel(at)yesql(dot)se>
Discussion: https://postgr.es/m/qtclihmrkq67ach3xjxyi4qcksstin5qxwsnkqefkmotxwh4g6%40ae2bj6jvcmry
Backpatch-through: 18

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/b738f7b679672ced054efc36e8da21c24d3a033b

Modified Files
--------------
src/interfaces/libpq-oauth/oauth-curl.c | 35 +++++++++++++++++++++++----------
1 file changed, 25 insertions(+), 10 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Tom Lane 2026-07-31 18:40:08 pgsql: On Windows, make link(2) report ENOTSUP when appropriate.
Previous Message Robert Haas 2026-07-31 15:57:54 pgsql: Prevent walsummarizer from getting stuck at a timeline switch.