pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: starbugs@qq.com
Subject: BUG #16191: Errors of division by zero occur in  several  files.
Date: Mon, 06 Jan 2020 04:00:17 +0000
Message-ID: <16191-e85c0af742abedd6@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      16191
Logged by:          Jian Zhang
Email address:      starbugs@qq.com
PostgreSQL version: 12.1
Operating system:   Linux
Description:        

We checked the codes in files “xlogreader.c”, “xlog.c”, “xlogutils.c”,
“xlogarchive.c”, “walsender.c”, “parsexlog.c”, “pg_rewind.c”,
“pg_resetwal.c”, “pg_waldump.c” and  “receivelog.c”, and found 20 errors
caused by the zero value used in division. There are five errors in file
“xlogreader.c” occurring in lines 755, 769, 819, 839 and 864 and the codes
of these five lines are the same: “XLogFileName(fname, state->readPageTLI,
segno, state->wal_segment_size);”. The function “XLogFileName” is defined in
file “xlog_internal.h” as “#define XLogFileName(fname, tli, logSegNo,
wal_segsz_bytes)	\
	snprintf(fname, MAXFNAMELEN, "%08X%08X%08X", tli,		\
			 (uint32) ((logSegNo) / XLogSegmentsPerXLogId(wal_segsz_bytes)), \
			 (uint32) ((logSegNo) % XLogSegmentsPerXLogId(wal_segsz_bytes)))”. So the
input parameter “state->wal_segment_size” may cause the zero return value of
function “XLogSegmentsPerXLogId” and the zero division will cause error.
For the file “xlog.c”, there are seven errors occurring in lines 3216, 3405,
3545, 3602, 3628, 3954 and 4022. The codes of these seven lines are the
same: “XLogFilePath(path, ThisTimeLineID, logsegno, wal_segment_size);”. The
function “XLogFilePath” is also defined in file “xlog_internal.h” as
“#define XLogFilePath(path, tli, logSegNo, wal_segsz_bytes)	\
	snprintf(path, MAXPGPATH, XLOGDIR "/%08X%08X%08X", tli,	\
			 (uint32) ((logSegNo) / XLogSegmentsPerXLogId(wal_segsz_bytes)), \
			 (uint32) ((logSegNo) % XLogSegmentsPerXLogId(wal_segsz_bytes)))”.
Similarly, the input parameter “wal_segment_size” may cause the zero return
value of function “XLogSegmentsPerXLogId” and the zero division will cause
error.
For the file “xlogutils.c”, the code in line 694 is “XLogFilePath(path, tli,
sendSegNo, segsize);”. For the file “xlogarchive.c”, the code in line 542 is
“XLogFileName(xlog, ThisTimeLineID, segno, wal_segment_size);”. For the file
“walsender.c”, the code in line 2433 is “XLogFilePath(path, curFileTimeLine,
sendSegNo, wal_segment_size);”. For the file “parsexlog.c”, the code in line
283 is “XLogFileName(xlogfname, targetHistory[private->tliIndex].tli,
xlogreadsegno, WalSegSz);”. For the file “pg_rewind.c”, the code in line 663
is “XLogFileName(xlogfilename, starttli, startsegno, WalSegSz);”. For the
file “pg_resetwal.c”, the code in line 1177 is “XLogFilePath(path,
ControlFile.checkPointCopy.ThisTimeLineID, newXlogSegNo, WalSegSz);”. For
the file “pg_waldump.c”, the code in line 339 is “XLogFileName(fname,
timeline_id, sendSegNo, WalSegSz);”. For the file “receivelog.c”, the code
in line 100 is “XLogFileName(current_walfile_name, stream->timeline, segno,
WalSegSz);”. Similarly, the input parameters may cause the zero return
values of function “XLogSegmentsPerXLogId” and the zero divisions will cause
errors.
The program should check the effectiveness (not zero) of the return value of
function “XLogSegmentsPerXLogId” in file “xlog_internal.h” to avoid this
type of errors.



view thread (2+ messages)  latest in thread

Message-ID: <16191-e85c0af742abedd6@postgresql.org>
Permalink:  ../16191-e85c0af742abedd6@postgresql.org/
Also on:    postgresql.org/message-id/16191-e85c0af742abedd6@postgresql.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-bugs@postgresql.org
  Cc: noreply@postgresql.org, starbugs@qq.com
  Subject: Re: BUG #16191: Errors of division by zero occur in  several  files.
  In-Reply-To: <16191-e85c0af742abedd6@postgresql.org>
  References: <16191-e85c0af742abedd6@postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox