Fix pgstat_report_replslot() to use proper data types for its arguments.
authorFujii Masao <fujii@postgresql.org>
Fri, 2 Apr 2021 08:27:31 +0000 (17:27 +0900)
committerFujii Masao <fujii@postgresql.org>
Fri, 2 Apr 2021 08:27:31 +0000 (17:27 +0900)
The caller of pgstat_report_replslot() passes int64 values to the function.
Also the function stores those values in PgStat_Counter (i.e., int64) fields
of PgStat_MsgReplSlot struct. But previously the function used "int" as
the data types of some arguments for those values, which could lead to
the overflow of values.

To avoid this risk, this commit fixes pgstat_report_replslot() to use
PgStat_Counter type for the arguments. Since they are the statistics counters,
PgStat_Counter, the data type used for counters, is used for them
instead of int64.

Reported-by: Vignesh C
Author: Vignesh C
Reviewed-by: Jeevan Ladhe, Fujii Masao
Discussion: https://postgr.es/m/CALDaNm080OpG=ZwOb0i8EyChH5SyHAMFWJCKaKTXmrfvJLbgaA@mail.gmail.com

src/backend/postmaster/pgstat.c
src/include/pgstat.h

index 4b9bcd2b41a44d349382f3039ae9e1a81c3fc8d4..2f3f378e633b2946b75799e4d8c63d4a4ac17907 100644 (file)
@@ -1773,8 +1773,10 @@ pgstat_report_tempfile(size_t filesize)
  * ----------
  */
 void
-pgstat_report_replslot(const char *slotname, int spilltxns, int spillcount,
-                      int spillbytes, int streamtxns, int streamcount, int streambytes)
+pgstat_report_replslot(const char *slotname, PgStat_Counter spilltxns,
+                      PgStat_Counter spillcount, PgStat_Counter spillbytes,
+                      PgStat_Counter streamtxns, PgStat_Counter streamcount,
+                      PgStat_Counter streambytes)
 {
    PgStat_MsgReplSlot msg;
 
index d699502cd9a5b7743342d4b97b01ced00b347558..fe6683cf5c8c2c3af6b3795b060569abc531a468 100644 (file)
@@ -1450,8 +1450,10 @@ extern void pgstat_report_recovery_conflict(int reason);
 extern void pgstat_report_deadlock(void);
 extern void pgstat_report_checksum_failures_in_db(Oid dboid, int failurecount);
 extern void pgstat_report_checksum_failure(void);
-extern void pgstat_report_replslot(const char *slotname, int spilltxns, int spillcount,
-                                  int spillbytes, int streamtxns, int streamcount, int streambytes);
+extern void pgstat_report_replslot(const char *slotname, PgStat_Counter spilltxns,
+                                  PgStat_Counter spillcount, PgStat_Counter spillbytes,
+                                  PgStat_Counter streamtxns, PgStat_Counter streamcount,
+                                  PgStat_Counter streambytes);
 extern void pgstat_report_replslot_drop(const char *slotname);
 
 extern void pgstat_initialize(void);