mirror of
https://github.com/postgres/postgres.git
synced 2025-06-11 20:28:21 +03:00
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:
@ -1489,7 +1489,7 @@ pgstat_reset_replslot_counter(const char *name)
|
|||||||
if (SlotIsPhysical(slot))
|
if (SlotIsPhysical(slot))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
memcpy(&msg.m_slotname, name, NAMEDATALEN);
|
strlcpy(msg.m_slotname, name, NAMEDATALEN);
|
||||||
msg.clearall = false;
|
msg.clearall = false;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1716,7 +1716,7 @@ pgstat_report_replslot(const char *slotname, int spilltxns, int spillcount,
|
|||||||
* Prepare and send the message
|
* Prepare and send the message
|
||||||
*/
|
*/
|
||||||
pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_REPLSLOT);
|
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_drop = false;
|
||||||
msg.m_spill_txns = spilltxns;
|
msg.m_spill_txns = spilltxns;
|
||||||
msg.m_spill_count = spillcount;
|
msg.m_spill_count = spillcount;
|
||||||
@ -1739,7 +1739,7 @@ pgstat_report_replslot_drop(const char *slotname)
|
|||||||
PgStat_MsgReplSlot msg;
|
PgStat_MsgReplSlot msg;
|
||||||
|
|
||||||
pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_REPLSLOT);
|
pgstat_setheader(&msg.m_hdr, PGSTAT_MTYPE_REPLSLOT);
|
||||||
memcpy(&msg.m_slotname, slotname, NAMEDATALEN);
|
strlcpy(msg.m_slotname, slotname, NAMEDATALEN);
|
||||||
msg.m_drop = true;
|
msg.m_drop = true;
|
||||||
pgstat_send(&msg, sizeof(PgStat_MsgReplSlot));
|
pgstat_send(&msg, sizeof(PgStat_MsgReplSlot));
|
||||||
}
|
}
|
||||||
@ -6880,7 +6880,9 @@ pgstat_recv_replslot(PgStat_MsgReplSlot *msg, int len)
|
|||||||
if (idx < 0)
|
if (idx < 0)
|
||||||
return;
|
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)
|
if (msg->m_drop)
|
||||||
{
|
{
|
||||||
/* Remove the replication slot statistics with the given name */
|
/* 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 */
|
/* Register new slot */
|
||||||
memset(&replSlotStats[nReplSlotStats], 0, sizeof(PgStat_ReplSlotStats));
|
memset(&replSlotStats[nReplSlotStats], 0, sizeof(PgStat_ReplSlotStats));
|
||||||
memcpy(&replSlotStats[nReplSlotStats].slotname, name, NAMEDATALEN);
|
strlcpy(replSlotStats[nReplSlotStats].slotname, name, NAMEDATALEN);
|
||||||
|
|
||||||
return nReplSlotStats++;
|
return nReplSlotStats++;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user