Show
Ignore:
Timestamp:
02/20/05 16:29:15 (8 years ago)
Author:
minaguib
Message:

* New safe.c with safe_malloc, safe_strdup, safe_asprintf and safe_vasprintf with propper logging and exit when error. Replaced all instances of original with safe versions in all files
* Fix memory leak in iptables_fw_counters_update

Files:
1 modified

Legend:

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

    r458 r467  
    4141#include "common.h" 
    4242 
     43#include "safe.h" 
    4344#include "conf.h" 
    4445#include "fw_iptables.h" 
     
    6970 
    7071    va_start(vlist, format); 
    71     vasprintf(&fmt_cmd, format, vlist); 
    72     asprintf(&cmd, "iptables %s", fmt_cmd); 
     72    safe_vasprintf(&fmt_cmd, format, vlist); 
     73         va_end(vlist); 
     74 
     75    safe_asprintf(&cmd, "iptables %s", fmt_cmd); 
     76 
     77    free(fmt_cmd); 
     78 
    7379    debug(LOG_DEBUG, "Executing command: %s", cmd); 
    7480         
    7581    rc = execute(cmd, fw_quiet); 
    7682 
    77     free(fmt_cmd); 
    7883    free(cmd); 
    7984 
     
    97102     
    98103    if (rule->block_allow == 1) { 
    99         mode = strdup("ACCEPT"); 
     104        mode = safe_strdup("ACCEPT"); 
    100105    } else { 
    101         mode = strdup("REJECT"); 
     106        mode = safe_strdup("REJECT"); 
    102107    } 
    103108     
     
    122127    /* XXX The buffer command, an automatic variable, will get cleaned 
    123128     * off of the stack when we return, so we strdup() it. */ 
    124     return(strdup(command)); 
     129    return(safe_strdup(command)); 
    125130} 
    126131 
     
    189194    config = config_get_config(); 
    190195         LOCK_CONFIG(); 
    191          gw_interface = strdup(config->gw_interface); 
     196         gw_interface = safe_strdup(config->gw_interface); 
    192197         gw_port = config->gw_port; 
    193198         UNLOCK_CONFIG(); 
     
    343348        int deleted = 0; 
    344349 
    345         asprintf(&command, "iptables -t %s -L %s -n --line-numbers -v", table, chain); 
     350        safe_asprintf(&command, "iptables -t %s -L %s -n --line-numbers -v", table, chain); 
    346351 
    347352        if ((p = popen(command, "r"))) { 
     
    356361                                if (sscanf(line, "%9[0-9]", rulenum) == 1) { 
    357362                                        /* Delete the rule: */ 
    358                                         asprintf(&command2, "-t %s -D %s %s", table, chain, rulenum); 
     363                                        safe_asprintf(&command2, "-t %s -D %s %s", table, chain, rulenum); 
    359364                                        iptables_do_command(command2); 
    360365                                        free(command2); 
     
    416421 
    417422    /* Look for outgoing traffic */ 
    418     asprintf(&script, "%s %s", "iptables", "-v -n -x -t mangle -L " TABLE_WIFIDOG_OUTGOING); 
    419     if (!(output = popen(script, "r"))) { 
     423    safe_asprintf(&script, "%s %s", "iptables", "-v -n -x -t mangle -L " TABLE_WIFIDOG_OUTGOING); 
     424    output = popen(script, "r"); 
     425    free(script); 
     426    if (!output) { 
    420427        debug(LOG_ERR, "popen(): %s", strerror(errno)); 
    421428        return -1; 
    422429    } 
    423     free(script); 
    424430 
    425431    /* skip the first two lines */ 
     
    453459 
    454460    /* Look for incoming traffic */ 
    455     asprintf(&script, "%s %s", "iptables", "-v -n -x -t mangle -L " TABLE_WIFIDOG_INCOMING); 
    456     if (!(output = popen(script, "r"))) { 
     461    safe_asprintf(&script, "%s %s", "iptables", "-v -n -x -t mangle -L " TABLE_WIFIDOG_INCOMING); 
     462    output = popen(script, "r"); 
     463    free(script); 
     464    if (!output) { 
    457465        debug(LOG_ERR, "popen(): %s", strerror(errno)); 
    458466        return -1; 
    459467    } 
    460     free(script); 
    461468 
    462469    /* skip the first two lines */