> From: "Theo de Raadt" <dera...@openbsd.org> > Date: Fri, 07 Apr 2023 05:39:00 -0600 > > Claudio Jeker <cje...@diehard.n-r-g.com> wrote: > > > On Fri, Apr 07, 2023 at 04:53:52PM +1000, David Gwynne wrote: > > > ethernet interfaces in device trees can have a "label" property which > > > is generally used (when it is used) to identify which connector it is on > > > the case or something like that. eg, eth2 in the turris omnia device > > > tree has 'label = "wan"' on the mvneta interface. > > > > > > ive been using labels in the dts recently to help me figure out what > > > goes where, so this has been useful to me. if/when we support switches > > > (eg mvsw), their ports are often labelled so i'd like to apply this idea > > > to them too. > > > > > > ok? > > > > I think doing this is OK but I'm not sure if the usage of OF_getprop() > > is correct. OF_getprop() uses 'memcpy(buf, data, min(len, buflen));' > > to fill the if_description buffer. So if the provided label is larger than > > sizeof(ifp->if_description) the description string is no longer NUL > > terminated. > > > I don't have a problem with the pre-population of the string either. > It's informational either way. > > But claudio is right, OF_getprop() is not like strlcpy, it behaves like > strncpy() so if you want to use it you need to copy n-1 bytes, and > manuall set the last byte to 0. Or make a new function which is more > suitable.
Might be worth adding a OF_getpropstr() function that behaves like strlcpy() in the sense that it makes sure the string is NUL-terminated. There are other places in drivers where this issue comes up.