BUG #16191: Errors of division by zero occur in several files. - Mailing list pgsql-bugs
From | PG Bug reporting form |
---|---|
Subject | BUG #16191: Errors of division by zero occur in several files. |
Date | |
Msg-id | 16191-e85c0af742abedd6@postgresql.org Whole thread Raw |
Responses |
Re: BUG #16191: Errors of division by zero occur in several files.
|
List | pgsql-bugs |
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.
pgsql-bugs by date: