Re: pg_rewind copies - Mailing list pgsql-hackers

From Peter Eisentraut
Subject Re: pg_rewind copies
Date
Msg-id 97e6edb1-0f9a-685a-c860-0d886d8f94ba@enterprisedb.com
Whole thread Raw
In response to Re: pg_rewind copies  (Daniel Gustafsson <daniel@yesql.se>)
Responses Re: pg_rewind copies
List pgsql-hackers
On 01.04.22 11:00, Daniel Gustafsson wrote:
> One small comment on the patch:
> 
> +   snprintf(srcpath, sizeof(srcpath), "%s/%s", datadir, path);
> 
> This should IMO check the returnvalue of snprintf to ensure it wasn't
> truncated.  While the risk is exceedingly small, a truncated filename might
> match another existing filename and the error not getting caught.  There is
> another instance just like this one in open_target_file() to which I think we
> should apply the same belts-and-suspenders treatment.  I've fixed this in the
> attached version which also have had a pg_indent run on top of a fresh rebase.

We use snprintf() like that countless times, and approximately none of 
them check for overflow.  So while you are right, this might not be the 
place to start a new policy.

If you don't like this approach, use psprintf() perhaps.



pgsql-hackers by date:

Previous
From: Robert Haas
Date:
Subject: Re: [PATCH v2] use has_privs_for_role for predefined roles
Next
From: Thomas Munro
Date:
Subject: Re: shared-memory based stats collector - v68