Show
Ignore:
Timestamp:
02/12/05 01:46:22 (8 years ago)
Author:
minaguib
Message:

Extra sanity checking the ip we read from the iptables output

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/wifidog/src/fw_iptables.c

    r441 r445  
    3535#include <string.h> 
    3636#include <pthread.h> 
     37#include <sys/socket.h> 
     38#include <netinet/in.h> 
     39#include <arpa/inet.h> 
    3740 
    3841#include "common.h" 
     
    351354    unsigned long int counter; 
    352355    t_client *p1; 
     356         struct in_addr tempaddr; 
    353357 
    354358    /* Look for outgoing traffic */ 
     
    368372        rc = fscanf(output, "%*s %lu %*s %*s %*s %*s %*s %s %*s %*s %*s %*s %*s 0x%*u", &counter, ip); 
    369373        if (2 == rc && EOF != rc) { 
     374                          /* Sanity*/ 
     375                          if (!inet_aton(ip, &tempaddr)) { 
     376                                  debug(LOG_WARNING, "I was supposed to read an IP address but instead got [%s] - ignoring it", ip); 
     377                                  continue; 
     378                          } 
    370379            debug(LOG_DEBUG, "Outgoing %s Bytes=%ld", ip, counter); 
    371380            LOCK_CLIENT_LIST(); 
     
    400409        rc = fscanf(output, "%*s %lu %*s %*s %*s %*s %*s %s %*s", &counter, ip); 
    401410        if (2 == rc && EOF != rc) { 
     411                          /* Sanity*/ 
     412                          if (!inet_aton(ip, &tempaddr)) { 
     413                                  debug(LOG_WARNING, "I was supposed to read an IP address but instead got [%s] - ignoring it", ip); 
     414                                  continue; 
     415                          } 
    402416            debug(LOG_DEBUG, "WIFI2FW %s Bytes=%ld", ip, counter); 
    403417            LOCK_CLIENT_LIST(); 
     
    432446        rc = fscanf(output, "%*s %lu %*s %*s %*s %*s %*s %*s %s", &counter, ip); 
    433447        if (2 == rc && EOF != rc) { 
     448                          /* Sanity*/ 
     449                          if (!inet_aton(ip, &tempaddr)) { 
     450                                  debug(LOG_WARNING, "I was supposed to read an IP address but instead got [%s] - ignoring it", ip); 
     451                                  continue; 
     452                          } 
    434453            debug(LOG_DEBUG, "Incoming %s Bytes=%ld", ip, counter); 
    435454            LOCK_CLIENT_LIST();