Re: Unbounded %s in sscanf - Mailing list pgsql-hackers

From Alvaro Herrera
Subject Re: Unbounded %s in sscanf
Date
Msg-id 202106281645.eb555hja6lxs@alvherre.pgsql
Whole thread Raw
In response to Unbounded %s in sscanf  (Daniel Gustafsson <daniel@yesql.se>)
List pgsql-hackers
On 2021-Jun-28, Daniel Gustafsson wrote:

> I happened to spot the below call in src/bin/pg_basebackup/streamutil.c which
> has an unbounded %s in the format.
> 
>     /* fetch xlog value and unit from the result */
>     if (sscanf(PQgetvalue(res, 0, 0), "%d%s", &xlog_val, xlog_unit) != 2)
> 
> There is no risk of overflow as the unit is defined to be at most 2 characters,
> but that's not explained (like how a similar %s is handled in pg_dump).  The
> attached adds a small explanation in the comment to save readers time from
> following the bouncing ball to make sure.

Can you attack the system by crafting malicious output from the query?
I think the answer is still no, because the output comes from the query
  SHOW wal_segment_size
which, if the attacker can control, the person running pg_basebackup has
way more serious problems.

But TBH it seems easy enough to limit to the output variable width.

-- 
Álvaro Herrera                            39°49'30"S 73°17'W
"How amazing is that? I call it a night and come back to find that a bug has
been identified and patched while I sleep."                (Robert Davidson)
               http://archives.postgresql.org/pgsql-sql/2006-03/msg00378.php



pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: Overflow hazard in pgbench
Next
From: Andrew Dunstan
Date:
Subject: Re: cleaning up PostgresNode.pm