pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #16191: Errors of division by zero occur in  several  files.
2+ messages / 2 participants
[nested] [flat]

* BUG #16191: Errors of division by zero occur in  several  files.
@ 2020-01-06 04:00  PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 1 reply; 2+ messages in thread

From: PG Bug reporting form @ 2020-01-06 04:00 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: starbugs@qq.com

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.



^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: BUG #16191: Errors of division by zero occur in  several  files.
@ 2020-01-06 05:26  Michael Paquier <michael@paquier.xyz>
  parent: PG Bug reporting form <noreply@postgresql.org>
  0 siblings, 0 replies; 2+ messages in thread

From: Michael Paquier @ 2020-01-06 05:26 UTC (permalink / raw)
  To: starbugs@qq.com; pgsql-bugs@lists.postgresql.org

On Mon, Jan 06, 2020 at 04:00:17AM +0000, PG Bug reporting form wrote:
> 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 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.

Reading the code is one thing.  Understanding it is another.  Have you
actually read the code and did you notice the assumptions behind the
ranges allowed by wal_segment_size (as known as WalSegMinSize and
WalSegMaxSize defined in xlog_internal.h)?  
--
Michael

Attachments:

  signature.asc (application/pgp-signature, 832B) download

^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2020-01-06 05:26 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2020-01-06 04:00 BUG #16191: Errors of division by zero occur in  several  files. PG Bug reporting form <noreply@postgresql.org>
2020-01-06 05:26 ` Michael Paquier <michael@paquier.xyz>

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