At Mon, 6 Jan 2025 15:23:45 -0500 (EST), Mouse <mouse%Rodents-Montreal.ORG@localhost> wrote: Subject: Re: Usage of strncpy in the kernel > > > All strlcpy() does extra is guarantee NUL-termination, > > Extra? Over strcpy and strncpy? Yes, it's what strlcpy() does over and above what strnpy() does. > No, that's not all. It also fills the rest, if any, of the destination > space with more NULs. (This can be useful to, for example, prevent > leaking kernel stack trash to userland.) That's what strncpy() does over and above what strlcpy() does. Each has an advantage (depending on the specific circumstances it is used in) over the other. Personally though I'll never use strlcpy(), either in-kernel or not. I prefer to be explicit about doing the NUL-termination when necessary after a call to strncpy() as that explicitly demonstrates what code is intending to do, and it accomplishes this using a well known standard function that's not system specific. Your idea about a wrapper to do the termination is interesting, but it's not one defined by any existing standard, and as such in some sense it actually hides the intention too much. -- Greg A. Woods <gwoods%acm.org@localhost> Kelowna, BC +1 250 762-7675 RoboHack <woods%robohack.ca@localhost> Planix, Inc. <woods%planix.com@localhost> Avoncote Farms <woods%avoncote.ca@localhost>
Attachment:
pgpnDPjju6aSs.pgp
Description: OpenPGP Digital Signature