summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmit Kapila2020-11-06 02:42:48 +0000
committerAmit Kapila2020-11-06 02:42:48 +0000
commit4f841ce3f7f4d429a3a275f82745d63c78cde4b2 (patch)
tree67d3968a270d60ac09715ecbfc68c43e1f92a665
parentefc5dcfd8ad4e1df633025d8a91b64cd44d93f42 (diff)
Use strlcpy instead of memcpy for copying the slot name in pgstat.c.
There is no outright bug here but it is better to be consistent with the usage at other places in the same file. In the passing, fix a wrong assertion in pgstat_recv_replslot. Author: Kyotaro Horiguchi Reviewed-by: Sawada Masahiko and Amit Kapila Discussion: https://postgr.es/m/20201104.175523.1704166915688949637.horikyota.ntt@gmail.com
-rw-r--r--src/backend/postmaster/pgstat.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/backend/postmaster/pgstat.c b/src/backend/postmaster/pgstat.c
index f1dca2f25b7..e76e627c6b2 100644
--- a/src/backend/postmaster/pgstat.c
+++ b/src/backend/postmaster/pgstat.c
@@ -1489,7 +1489,7 @@ pgstat_reset_replslot_counter(const char *name)
if (SlotIsPhysical(slot))
return;
- memcpy(&msg.m_slotname, name, NAMEDATALEN);
+ strlcpy(msg.m_slotname, name, NAMEDATALEN);
msg.clearall = false;
}
else
@@ -1716,7 +1716,7 @@ pgstat_report_replslot(const char *slotname, int spilltxns, int spillcount,
* Prepare and send the message
*/
pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_REPLSLOT);
- memcpy(&msg.m_slotname, slotname, NAMEDATALEN);
+ strlcpy(msg.m_slotname, slotname, NAMEDATALEN);
msg.m_drop = false;
msg.m_spill_txns = spilltxns;
msg.m_spill_count = spillcount;
@@ -1739,7 +1739,7 @@ pgstat_report_replslot_drop(const char *slotname)
PgStat_MsgReplSlot msg;
pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_REPLSLOT);
- memcpy(&msg.m_slotname, slotname, NAMEDATALEN);
+ strlcpy(msg.m_slotname, slotname, NAMEDATALEN);
msg.m_drop = true;
pgstat_send(&msg, sizeof(PgStat_MsgReplSlot));
}
@@ -6880,7 +6880,9 @@ pgstat_recv_replslot(PgStat_MsgReplSlot *msg, int len)
if (idx < 0)
return;
- Assert(idx >= 0 && idx <= max_replication_slots);
+ /* it must be a valid replication slot index */
+ Assert(idx >= 0 && idx < max_replication_slots);
+
if (msg->m_drop)
{
/* Remove the replication slot statistics with the given name */
@@ -7113,7 +7115,7 @@ pgstat_replslot_index(const char *name, bool create_it)
/* Register new slot */
memset(&replSlotStats[nReplSlotStats], 0, sizeof(PgStat_ReplSlotStats));
- memcpy(&replSlotStats[nReplSlotStats].slotname, name, NAMEDATALEN);
+ strlcpy(replSlotStats[nReplSlotStats].slotname, name, NAMEDATALEN);
return nReplSlotStats++;
}