Page MenuHomeFreeBSD

ifconfig: Use strlcpy() instead of strncpy() for interface name copy
ClosedPublic

Authored by amy.vargas_netapp.com on Fri, Jan 16, 9:53 PM.
Tags
None
Referenced Files
Unknown Object (File)
Thu, Jan 22, 5:26 PM
Unknown Object (File)
Wed, Jan 21, 10:30 AM
Unknown Object (File)
Tue, Jan 20, 8:20 PM
Unknown Object (File)
Tue, Jan 20, 12:11 PM
Unknown Object (File)
Mon, Jan 19, 1:45 AM
Unknown Object (File)
Sun, Jan 18, 5:35 PM
Unknown Object (File)
Sun, Jan 18, 5:24 PM
Unknown Object (File)
Sun, Jan 18, 1:54 PM
Subscribers

Details

Summary

Replace strncpy() with strlcpy() when copying the interface name into ifr.ifr_name in link_status(). This ensures proper NUL-termination and addresses a potential issue flagged by Coverity static analysis.

No functional change intended.

Test Plan

Build completed successfully

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

This revision is now accepted and ready to land.Sat, Jan 17, 9:54 AM
sbin/ifconfig/af_link.c
137

OK. This is a good change since ifr_name is an array of IF_NAMESIZE bytes (currently 16) that's documented to be null terminated:

/*
 * Length of interface external name, including terminating '\0'.
 * Note: this is the same size as a generic device's external name.
 */

Though I'm not entirely sure what a 'generic device' might be, since newbus names can be longer than 16 characters... But I guess that part doesn't matter. 'including the terminating '\0'. While one could pass in a mal-formed ifa structure, pointing to a device that's longer than allowed and this would silently truncate it, the worst that could happen is that the kernel can't find the device for the SIOCGHWADDDR call and the error would be signalled there.

tl;dr: Looks great!