Theo Buehler <t...@theobuehler.org> wrote: > On Fri, Aug 04, 2023 at 11:40:36AM +0200, Claudio Jeker wrote: > > When copying the shutdown reason from ctl_neighbor into the peer struct > > the strlcpy needs a NUL terminated string input. This may not be the case > > so we should be more careful here. > > I see two ways to fix this. > > a) force in a NUL before callin strlcpy() as done below. > > b) use memcpy() and then force terminate p->conf.reason. > > I think either approach is fine. A third option would be > > c) snprintf with "%.*s"
To me that always smells like "it isn't a string, we'll remember that, and handle the situation later". But.. it... isn't... a string. Gross. So I would always lean towards code that insists on passing the 0 byte at every stage, even if it has to also pass strlen+1 for a block region size. And if you find one of these to copy, always convert it to a real string ASAP.