aboutsummaryrefslogtreecommitdiff
path: root/plugins-root/check_dhcp.c
diff options
context:
space:
mode:
authorGravatar Holger Weiss <hweiss@users.sourceforge.net> 2007-07-26 00:46:42 +0000
committerGravatar Holger Weiss <hweiss@users.sourceforge.net> 2007-07-26 00:46:42 +0000
commit6f60c0ac81933976fdc2e7e763fc1d03312e3b3f (patch)
tree5f94829c7e5afc3c5c3fbc08347faad18829cda8 /plugins-root/check_dhcp.c
parentbd8427362889c23ac963f8e032ee7a6d877b8969 (diff)
downloadmonitoring-plugins-6f60c0ac81933976fdc2e7e763fc1d03312e3b3f.tar.gz
Make sure strncpy(3)d buffers are nul-terminated.
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@1764 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'plugins-root/check_dhcp.c')
-rw-r--r--plugins-root/check_dhcp.c9
1 files changed, 6 insertions, 3 deletions
diff --git a/plugins-root/check_dhcp.c b/plugins-root/check_dhcp.c
index 904d43ef..db673893 100644
--- a/plugins-root/check_dhcp.c
+++ b/plugins-root/check_dhcp.c
@@ -313,7 +313,8 @@ int get_hardware_address(int sock,char *interface_name){
#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 @@ int create_dhcp_socket(void){
/* 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 */