diff options
Diffstat (limited to 'rpcapd/fileconf.c')
| -rw-r--r-- | rpcapd/fileconf.c | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/rpcapd/fileconf.c b/rpcapd/fileconf.c index 2f15c014204f..c051f887ead6 100644 --- a/rpcapd/fileconf.c +++ b/rpcapd/fileconf.c @@ -39,7 +39,6 @@ #include <stdio.h> #include <string.h> -#include <ctype.h> #include <signal.h> #include <pcap.h> // for PCAP_ERRBUF_SIZE @@ -59,6 +58,16 @@ static char *skipws(char *ptr); +/* + * Locale-independent version checks for alphabetical and alphanumerical + * characters that also can handle being handed a char value that might + * be negative. + */ +#define FILECONF_ISALPHA(c) \ + (((c) >= 'A' && (c) <= 'Z') || ((c) >= 'a' && (c) <= 'z')) +#define FILECONF_ISALNUM(c) \ + (FILECONF_ISALPHA(c) || ((c) >= '0' && (c) <= '9')) + void fileconf_read(void) { FILE *fp; @@ -135,8 +144,7 @@ void fileconf_read(void) // Is the next character alphabetic? If not, // this isn't a valid parameter name. // - if (!isascii((unsigned char)*ptr) || - !isalpha((unsigned char)*ptr)) + if (FILECONF_ISALPHA(*ptr)) { rpcapd_log(LOGPRIO_ERROR, "%s, line %u doesn't have a valid parameter name", @@ -150,8 +158,7 @@ void fileconf_read(void) // That's the name of the parameter being set. // param = ptr; - while (isascii((unsigned char)*ptr) && - (isalnum((unsigned char)*ptr) || *ptr == '-' || *ptr == '_')) + while (FILECONF_ISALNUM(*ptr) || *ptr == '-' || *ptr == '_') ptr++; // @@ -234,13 +241,15 @@ void fileconf_read(void) ptr += toklen; // skip to the terminator if (toklen == 0) { - if (isascii((unsigned char)*ptr) && - (isspace((unsigned char)*ptr) || *ptr == '#' || *ptr == '\0')) + if (*ptr == ' ' || *ptr == '\t' || + *ptr == '\r' || *ptr == '\n' || + *ptr == '#' || *ptr == '\0') { // // The first character it saw // was a whitespace character - // or a comment character. + // or a comment character, + // or we ran out of characters. // This means that there's // no value. // @@ -377,7 +386,7 @@ void fileconf_read(void) // // Append this to the host list. - // Save the curren end-of-string for the + // Save the current end-of-string for the // host list, in case the new host doesn't // fit, so that we can discard the partially- // copied host name. @@ -498,8 +507,7 @@ int fileconf_save(const char *savefile) fprintf(fp, "# Hosts which are allowed to connect to this server (passive mode)\n"); fprintf(fp, "# Format: PassiveClient = <name or address>\n\n"); - strncpy(temphostlist, hostlist, MAX_HOST_LIST); - temphostlist[MAX_HOST_LIST] = 0; + pcap_strlcpy(temphostlist, hostlist, sizeof (temphostlist)); token = pcap_strtok_r(temphostlist, RPCAP_HOSTLIST_SEP, &lasts); while(token != NULL) @@ -548,7 +556,7 @@ int fileconf_save(const char *savefile) // static char *skipws(char *ptr) { - while (isascii((unsigned char)*ptr) && isspace((unsigned char)*ptr)) { + while (*ptr == ' ' || *ptr == '\t' || *ptr == '\r' || *ptr == '\n') { if (*ptr == '\r' || *ptr == '\n') return NULL; *ptr++ = '\0'; |
