[Nagiosplug-checkins] SF.net SVN: nagiosplug: [1764] nagiosplug/trunk/plugins-root/check_dhcp.c
hweiss at users.sourceforge.net
hweiss at users.sourceforge.net
Thu Jul 26 02:46:42 CEST 2007
Revision: 1764
http://nagiosplug.svn.sourceforge.net/nagiosplug/?rev=1764&view=rev
Author: hweiss
Date: 2007-07-25 17:46:42 -0700 (Wed, 25 Jul 2007)
Log Message:
-----------
Make sure strncpy(3)d buffers are nul-terminated.
Modified Paths:
--------------
nagiosplug/trunk/plugins-root/check_dhcp.c
Modified: nagiosplug/trunk/plugins-root/check_dhcp.c
===================================================================
--- nagiosplug/trunk/plugins-root/check_dhcp.c 2007-07-26 00:07:19 UTC (rev 1763)
+++ nagiosplug/trunk/plugins-root/check_dhcp.c 2007-07-26 00:46:42 UTC (rev 1764)
@@ -313,7 +313,8 @@
#if defined(__linux__)
struct ifreq ifr;
- strncpy((char *)&ifr.ifr_name,interface_name,sizeof(ifr.ifr_name));
+ strncpy((char *)&ifr.ifr_name,interface_name,sizeof(ifr.ifr_name)-1);
+ ifr.ifr_name[sizeof(ifr.ifr_name)-1]='\0';
/* try and grab hardware address of requested interface */
if(ioctl(sock,SIOCGIFHWADDR,&ifr)<0){
@@ -773,14 +774,16 @@
/* bind socket to interface */
#if defined(__linux__)
- strncpy(interface.ifr_ifrn.ifrn_name,network_interface_name,IFNAMSIZ);
+ strncpy(interface.ifr_ifrn.ifrn_name,network_interface_name,IFNAMSIZ-1);
+ interface.ifr_ifrn.ifrn_name[IFNAMSIZ-1]='\0';
if(setsockopt(sock,SOL_SOCKET,SO_BINDTODEVICE,(char *)&interface,sizeof(interface))<0){
printf(_("Error: Could not bind socket to interface %s. Check your privileges...\n"),network_interface_name);
exit(STATE_UNKNOWN);
}
#else
- strncpy(interface.ifr_name,network_interface_name,IFNAMSIZ);
+ strncpy(interface.ifr_name,network_interface_name,IFNAMSIZ-1);
+ interface.ifr_name[IFNAMSIZ-1]='\0';
#endif
/* bind the socket */
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Commits
mailing list