回复: 回复: Fix potential overflow risks from wcscpy and sprintf

From: Yan Haibo <haibo(dot)yan(at)hotmail(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Peter Eisentraut <peter(at)eisentraut(dot)org>, "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: 回复: 回复: Fix potential overflow risks from wcscpy and sprintf
Date: 2025-06-16 19:20:38
Message-ID: CH3PR08MB86104C3686D18CD089470F8BFA70A@CH3PR08MB8610.namprd08.prod.outlook.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Thank you. Tom. I agree that fixing the sprintf usage is not well-timed at the moment, so I’ve removed that change.
Regarding the use of wcsncpy with LOCALE_NAME_MAX_LENGTH - 1, it is a precaution in case the input string is not null-terminated.
Thanks again,
Haibo

________________________________
发件人: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
发送时间: 2025年6月16日 11:28
收件人: Yan Haibo <haibo(dot)yan(at)hotmail(dot)com>
抄送: Peter Eisentraut <peter(at)eisentraut(dot)org>; pgsql-hackers(at)lists(dot)postgresql(dot)org <pgsql-hackers(at)lists(dot)postgresql(dot)org>
主题: Re: 回复: Fix potential overflow risks from wcscpy and sprintf

Yan Haibo <haibo(dot)yan(at)hotmail(dot)com> writes:
> Thank you. Peter. It seems the patch may have been lost during our earlier communication, so I¡¯ve reattached it here.
> I hope it comes through correctly this time.

Thanks for the patch.

Using wcsncpy in search_locale_enum() seems fine, assuming it exists
on Windows (note that code is Windows-only, possibly explaining why
we've not seen other static-analysis reports). I doubt there's any
actual bug there, since we're relying on Windows' own
LOCALE_NAME_MAX_LENGTH constant; but I agree the chain of reasoning
is kind of long. (But shouldn't you write LOCALE_NAME_MAX_LENGTH
not LOCALE_NAME_MAX_LENGTH - 1?)

I'm unexcited about the guc.c changes. There is visibly no bug
there. The only reason to change it would be if we were going
to introduce a strict project policy against using sprintf(),
which we're not likely to given that there are hundreds of other
occurrences in our code base. I don't see a reason to think
that these three are more pressing than the others.

regards, tom lane

Attachment Content-Type Size
0001-Mitigate-potential-overflow-risks-from-wcscpy.patch application/octet-stream 1.3 KB

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Corey Huinker 2025-06-16 19:35:48 Re: pg_dump --with-* options
Previous Message Arseniy Mukhin 2025-06-16 19:09:25 Re: Amcheck verification of GiST and GIN