Re: Replace remaining StrNCpy() by strlcpy()
Tom Lane <tgl@sss.pgh.pa.us>
From: Tom Lane <tgl@sss.pgh.pa.us>
To: David Rowley <dgrowleyml@gmail.com>
Cc: Peter Eisentraut <peter.eisentraut@2ndquadrant.com>,
pgsql-hackers <pgsql-hackers@postgresql.org>
Date: 2020-08-03T11:38:53Z
Lists: pgsql-hackers
David Rowley <dgrowleyml@gmail.com> writes: > - StrNCpy(msg.m_xlog, xlog, sizeof(msg.m_xlog)); > + strlcpy(msg.m_xlog, xlog, sizeof(msg.m_xlog)); > Will mean that we'll now no longer zero the full length of the m_xlog > field after the end of the string. Won't that mean we'll start writing > junk bytes to the stats collector? StrNCpy doesn't zero-fill the destination today either (except for the very last byte). If you need that, you need to memset the dest buffer ahead of time. I didn't review the patch in complete detail, but the principle seems sound to me, and strlcpy is surely more standard than StrNCpy. regards, tom lane
Commits
-
Replace remaining StrNCpy() by strlcpy()
- 1784f278a638 14.0 landed