@@ -165,7 +165,8 @@ get_iface_ip(const char *ifname)
165
165
}
166
166
167
167
/* Get IP of internal interface */
168
- strcpy (if_data .ifr_name , ifname );
168
+ strncpy (if_data .ifr_name , ifname , 15 );
169
+ if_data .ifr_name [15 ] = '\0' ;
169
170
170
171
/* Get the IP address */
171
172
if (ioctl (sockd , SIOCGIFADDR , & if_data ) < 0 ) {
@@ -188,7 +189,8 @@ get_iface_mac(const char *ifname)
188
189
struct ifreq ifr ;
189
190
char * hwaddr , mac [13 ];
190
191
191
- strcpy (ifr .ifr_name , ifname );
192
+ strncpy (ifr .ifr_name , ifname , 15 );
193
+ ifr .ifr_name [15 ] = '\0' ;
192
194
193
195
s = socket (AF_INET , SOCK_DGRAM , 0 );
194
196
if (-1 == s ) {
@@ -229,14 +231,16 @@ get_ext_iface(void)
229
231
input = fopen ("/proc/net/route" , "r" );
230
232
if (NULL == input ) {
231
233
debug (LOG_ERR , "Could not open /proc/net/route (%s)." , strerror (errno ));
234
+ free (gw );
235
+ free (device );
232
236
return NULL ;
233
237
}
234
238
while (!feof (input )) {
235
239
/* XXX scanf(3) is unsafe, risks overrun */
236
- if ((fscanf (input , "%s %s %*s %*s %*s %*s %*s %*s %*s %*s %*s\n" , device , gw ) == 2 )
240
+ if ((fscanf (input , "%15s %15s %*s %*s %*s %*s %*s %*s %*s %*s %*s\n" , device , gw ) == 2 )
237
241
&& strcmp (gw , "00000000" ) == 0 ) {
238
242
free (gw );
239
- debug (LOG_INFO , "get_ext_iface(): Detected %s as the default interface after try %d" , device , i );
243
+ debug (LOG_INFO , "get_ext_iface(): Detected %s as the default interface after trying %d" , device , i );
240
244
fclose (input );
241
245
return device ;
242
246
}
0 commit comments