Bug in writeTimeLineHistory

Started by Fujii Masaoabout 15 years ago2 messages
#1Fujii Masao
masao.fujii@gmail.com
1 attachment(s)

Hi,

--------------
if (recoveryTarget == RECOVERY_TARGET_XID)
snprintf(buffer, sizeof(buffer),
"%s%u\t%s\t%s transaction %u\n",
(srcfd < 0) ? "" : "\n",
parentTLI,
xlogfname,
recoveryStopAfter ? "after" : "before",
recoveryStopXid);
if (recoveryTarget == RECOVERY_TARGET_TIME)
snprintf(buffer, sizeof(buffer),
"%s%u\t%s\t%s %s\n",
(srcfd < 0) ? "" : "\n",
parentTLI,
xlogfname,
recoveryStopAfter ? "after" : "before",
timestamptz_to_str(recoveryStopTime));
else
snprintf(buffer, sizeof(buffer),
"%s%u\t%s\tno recovery target specified\n",
(srcfd < 0) ? "" : "\n",
parentTLI,
xlogfname);
--------------

In writeTimeLineHistory, the result of the above first snprintf is always
overwritten by the following snprintf wrongly. I guess we forgot putting
"else" in the second "if" statement. I attached the very simple patch.

Since this bug was introduced in v9.0, the patch needs to be backported
to 9.0.

Regards,

--
Fujii Masao
NIPPON TELEGRAPH AND TELEPHONE CORPORATION
NTT Open Source Software Center

Attachments:

add_else_v1.patchapplication/octet-stream; name=add_else_v1.patchDownload
*** a/src/backend/access/transam/xlog.c
--- b/src/backend/access/transam/xlog.c
***************
*** 4369,4375 **** writeTimeLineHistory(TimeLineID newTLI, TimeLineID parentTLI,
  				 xlogfname,
  				 recoveryStopAfter ? "after" : "before",
  				 recoveryStopXid);
! 	if (recoveryTarget == RECOVERY_TARGET_TIME)
  		snprintf(buffer, sizeof(buffer),
  				 "%s%u\t%s\t%s %s\n",
  				 (srcfd < 0) ? "" : "\n",
--- 4369,4375 ----
  				 xlogfname,
  				 recoveryStopAfter ? "after" : "before",
  				 recoveryStopXid);
! 	else if (recoveryTarget == RECOVERY_TARGET_TIME)
  		snprintf(buffer, sizeof(buffer),
  				 "%s%u\t%s\t%s %s\n",
  				 (srcfd < 0) ? "" : "\n",
#2Simon Riggs
simon@2ndQuadrant.com
In reply to: Fujii Masao (#1)
Re: Bug in writeTimeLineHistory

Agreed, committed and backpatched.

On Thu, 2010-10-14 at 14:11 +0900, Fujii Masao wrote:

Hi,

--------------
if (recoveryTarget == RECOVERY_TARGET_XID)
snprintf(buffer, sizeof(buffer),
"%s%u\t%s\t%s transaction %u\n",
(srcfd < 0) ? "" : "\n",
parentTLI,
xlogfname,
recoveryStopAfter ? "after" : "before",
recoveryStopXid);
if (recoveryTarget == RECOVERY_TARGET_TIME)
snprintf(buffer, sizeof(buffer),
"%s%u\t%s\t%s %s\n",
(srcfd < 0) ? "" : "\n",
parentTLI,
xlogfname,
recoveryStopAfter ? "after" : "before",
timestamptz_to_str(recoveryStopTime));
else
snprintf(buffer, sizeof(buffer),
"%s%u\t%s\tno recovery target specified\n",
(srcfd < 0) ? "" : "\n",
parentTLI,
xlogfname);
--------------

In writeTimeLineHistory, the result of the above first snprintf is always
overwritten by the following snprintf wrongly. I guess we forgot putting
"else" in the second "if" statement. I attached the very simple patch.

Since this bug was introduced in v9.0, the patch needs to be backported
to 9.0.

Regards,

--
Simon Riggs www.2ndQuadrant.com
PostgreSQL Development, 24x7 Support, Training and Services