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
This commit is contained in:
parent
efc5dcfd8a
commit
4f841ce3f7
@ -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++;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user