shadow-maint / shadow

Upstream shadow tree
Other
305 stars 231 forks source link

Replace strncpy(3) #468

Closed alejandro-colomar closed 9 months ago

alejandro-colomar commented 2 years ago

Hi,

I've seen strncpy(3) being used in the code for copying strings. Ideally, those could be replaced by strlcpy(3bsd), if libbsd can be depended upon on non-BSD systems. Otherwise, memccpy(3) is the second best replacement.

Problems of strncpy(3):

In some cases, the writing of the whole buffer with 0s might be actually good, to avoid leaking old values. However, that's better achieved by a separate function call that zeroes the buffer, so I don't think strncpy(3) deserves usage in this project.

What are your thoughts?

alejandro-colomar commented 2 years ago

See the following mailing list thread for a better proposal of replacement: https://alioth-lists.debian.net/pipermail/pkg-shadow-devel/2022-February/013142.html