pg_controldata: Fix possible errors on corrupted pg_control
authorAlexander Korotkov <akorotkov@postgresql.org>
Tue, 4 Feb 2025 22:15:17 +0000 (00:15 +0200)
committerAlexander Korotkov <akorotkov@postgresql.org>
Tue, 4 Feb 2025 22:45:49 +0000 (00:45 +0200)
commitff1975ddd0270703306dee56601b17742d0934b6
tree88888782691d7c8e9367d0a07120e72f7f363d51
parent627d63419e22054551327216d2b2de3e6977fade
pg_controldata: Fix possible errors on corrupted pg_control

Protect against malformed timestamps.  Also protect against negative WalSegSz
as it triggers division by zero:

((0x100000000UL) / (WalSegSz)) can turn into zero in

XLogFileName(xlogfilename, ControlFile->checkPointCopy.ThisTimeLineID,
             segno, WalSegSz);

because if WalSegSz is -1 then by arithmetic rules in C we get
0x100000000UL / 0xFFFFFFFFFFFFFFFFUL == 0.

Author: Ilyasov Ian <ianilyasov@outlook.com>
Author: Anton Voloshin <a.voloshin@postgrespro.ru>
Backpatch-through: 13
src/bin/pg_controldata/pg_controldata.c