postgres.git / summary / log / commit / refs
commit 4f841ce3f7f4d429a3a275f82745d63c78cde4b2
Author: Amit Kapila <akapila@postgresql.org>
Date: Fri Nov 06 02:42:48 2020 +0000
First released in: 14.0
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
src/backend/postmaster/pgstat.c | 12 +++++++-----
1 file 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++;
}
[parent: efc5dcfd8ad4]