Show
Ignore:
Timestamp:
09/16/09 04:19:24 (5 years ago)
Author:
Theo Schlossnagle <jesus@omniti.com>
git-committer:
Theo Schlossnagle <jesus@omniti.com> 1253074764 +0000
git-parent:

[6298e33b2e6517913907fa76bd9af5a1ea28b922]

git-author:
Theo Schlossnagle <jesus@omniti.com> 1253074764 +0000
Message:

robust input validation, refs #171

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • src/noit_conf.c

    r4fd2f1f r7010bc5  
    152152             err->domain, err->code, err->message); 
    153153} 
     154 
     155 
     156DECLARE_CHECKER(name) 
    154157void noit_conf_init(const char *toplevel) { 
    155158  int i; 
    156159  char keystr[256]; 
     160  COMPILE_CHECKER(name, "^[-_\\.:/a-zA-Z0-9]+$"); 
    157161  xmlSetGenericErrorFunc(noit_error, noit_conf_xml_error_func); 
    158162  xmlSetStructuredErrorFunc(noit_error, noit_conf_xml_error_ext_func); 
     
    423427  return 1; 
    424428} 
     429int noit_conf_string_to_int(const char *str) { 
     430  int base = 10; 
     431  if(!str) return 0; 
     432  if(str[0] == '0') { 
     433    if(str[1] == 'x') base = 16; 
     434    else base = 8; 
     435  } 
     436  return strtol(str, NULL, base); 
     437} 
    425438int noit_conf_get_int(noit_conf_section_t section, 
    426439                      const char *path, int *value) { 
    427440  char *str; 
    428   long longval; 
    429441  if(_noit_conf_get_string(section,NULL,path,&str)) { 
    430     int base = 10; 
    431     if(str[0] == '0') { 
    432       if(str[1] == 'x') base = 16; 
    433       else base = 8; 
    434     } 
    435     longval = strtol(str, NULL, base); 
     442    *value = (int)noit_conf_string_to_int(str); 
    436443    xmlFree(str); 
    437     *value = (int)longval; 
    438444    return 1; 
    439445  } 
     
    446452  return noit_conf_set_string(section,path,buffer); 
    447453} 
     454float noit_conf_string_to_float(const char *str) { 
     455  if(!str) return 0.0; 
     456  return atof(str); 
     457} 
    448458int noit_conf_get_float(noit_conf_section_t section, 
    449459                        const char *path, float *value) { 
    450460  char *str; 
    451461  if(_noit_conf_get_string(section,NULL,path,&str)) { 
    452     *value = atof(str); 
     462    *value = noit_conf_string_to_float(str); 
    453463    xmlFree(str); 
    454464    return 1; 
     
    462472  return noit_conf_set_string(section,path,buffer); 
    463473} 
     474noit_boolean noit_conf_string_to_boolean(const char *str) { 
     475  if(!str) return noit_false; 
     476  if(!strcasecmp(str, "true") || !strcasecmp(str, "on")) return noit_true; 
     477  return noit_false; 
     478} 
    464479int noit_conf_get_boolean(noit_conf_section_t section, 
    465480                          const char *path, noit_boolean *value) { 
    466481  char *str; 
    467482  if(_noit_conf_get_string(section,NULL,path,&str)) { 
    468     if(!strcasecmp(str, "true") || 
    469        !strcasecmp(str, "on")) *value = noit_true; 
    470     else *value = noit_false; 
     483    *value = noit_conf_string_to_boolean(str); 
    471484    xmlFree(str); 
    472485    return 1;