Skip to content

Commit

Permalink
Updated uses of the ctype function to support explict casting of the …
Browse files Browse the repository at this point in the history
…arguments

to (int)(unsigned char).



git-svn-id: svn://svn.insecure.org/nmap@14789 e0a8ed71-7df4-0310-8962-fdc924857419
  • Loading branch information
josh committed Aug 6, 2009
1 parent 5e66d28 commit 9c3c689
Show file tree
Hide file tree
Showing 14 changed files with 73 additions and 72 deletions.
6 changes: 3 additions & 3 deletions MACLookup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -156,18 +156,18 @@ static void mac_prefix_init() {
while(fgets(line, sizeof(line), fp)) {
lineno++;
if (*line == '#') continue;
if (!isxdigit(*line)) {
if (!isxdigit((int) (unsigned char) *line)) {
error("Parse error one line #%d of %s. Giving up parsing.", lineno, filename);
break;
}
/* First grab the prefix */
pfx = strtol(line, &endptr, 16);
if (!endptr || !isspace(*endptr)) {
if (!endptr || !isspace((int) (unsigned char) *endptr)) {
error("Parse error one line #%d of %s. Giving up parsing.", lineno, filename);
break;
}
/* Now grab the vendor */
while(*endptr && isspace(*endptr)) endptr++;
while(*endptr && isspace((int) (unsigned char) *endptr)) endptr++;
assert(*endptr);
p = endptr;
while(*endptr && *endptr != '\n' && *endptr != '\r') endptr++;
Expand Down
2 changes: 1 addition & 1 deletion Target.cc
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ void Target::setHostName(char *name) {
while (*p) {
// I think only a-z A-Z 0-9 . and - are allowed, but I'll be a little more
// generous.
if (!isalnum(*p) && !strchr(".-+=:_~*", *p)) {
if (!isalnum((int) (unsigned char) *p) && !strchr(".-+=:_~*", *p)) {
log_write(LOG_STDOUT, "Illegal character(s) in hostname -- replacing with '*'\n");
*p = '*';
}
Expand Down
7 changes: 4 additions & 3 deletions TargetGroup.cc
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ int TargetGroup::parse_expr(const char * const target_expr, int af) {

*s = '\0'; /* Make sure target_net is terminated before the /## */
s++; /* Point s at the netmask */
if (!isdigit(*s)) {
if (!isdigit((int) (unsigned char) *s)) {
error("Illegal netmask value, must be /0 - /32 . Assuming /32 (one host)");
netmask = 32;
} else {
Expand All @@ -199,7 +199,8 @@ int TargetGroup::parse_expr(const char * const target_expr, int af) {
} else
netmask = 32;
for(i=0; *(hostexp + i); i++)
if (isupper((int) *(hostexp +i)) || islower((int) *(hostexp +i))) {
if (isupper((int) (unsigned char) *(hostexp +i)) ||
islower((int) (unsigned char) *(hostexp +i))) {
namedhost = 1;
break;
}
Expand Down Expand Up @@ -251,7 +252,7 @@ int TargetGroup::parse_expr(const char * const target_expr, int af) {
*r = '\0';
addy[i] = r + 1;
}
else if (*r != '*' && *r != ',' && *r != '-' && !isdigit((int)*r))
else if (*r != '*' && *r != ',' && *r != '-' && !isdigit((int) (unsigned char) *r))
fatal("Invalid character in host specification. Note in particular that square brackets [] are no longer allowed. They were redundant and can simply be removed.");
*r++;
}
Expand Down
22 changes: 11 additions & 11 deletions nmap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ static int parse_scanflags(char *arg) {
int flagval = 0;
char *end = NULL;

if (isdigit(arg[0])) {
if (isdigit((int) (unsigned char) arg[0])) {
flagval = strtol(arg, &end, 0);
if (*end || flagval < 0 || flagval > 255) return -1;
} else {
Expand Down Expand Up @@ -1461,7 +1461,7 @@ int nmap_main(int argc, char *argv[]) {
const char *p = spoofmac;
while(*p) {
if (*p == ':') p++;
if (isxdigit(*p) && isxdigit(*(p+1))) {
if (isxdigit((int) (unsigned char) *p) && isxdigit((int) (unsigned char) *(p+1))) {
if (pos >= 6) fatal("Bogus --spoof-mac value encountered (%s) -- only up to 6 bytes permitted", spoofmac);
tmphex[0] = *p; tmphex[1] = *(p+1); tmphex[2] = '\0';
mac_data[pos] = (u8) strtol(tmphex, NULL, 16);
Expand Down Expand Up @@ -2055,7 +2055,7 @@ int gather_logfile_resumption_state(char *fname, int *myargc, char ***myargv) {
if ((p = strstr(filestr, " as: ")))
p += 5;
else fatal("Unable to parse supposed log file %s. Are you sure this is an Nmap output file?", fname);
while(*p && !isspace((int) *p))
while(*p && !isspace((int) (unsigned char) *p))
p++;
if (!*p) fatal("Unable to parse supposed log file %s. Sorry", fname);
p++; /* Skip the space between program name and first arg */
Expand Down Expand Up @@ -2106,7 +2106,7 @@ int gather_logfile_resumption_state(char *fname, int *myargc, char ***myargv) {
if (q) {
while((q = strstr(q, "\nAll "))) {
q+= 5;
while(isdigit(*q)) q++;
while(isdigit((int) (unsigned char) *q)) q++;
if (strncmp(q, " scanned ports on", 17) == 0)
found = q;
}
Expand Down Expand Up @@ -2355,7 +2355,7 @@ static void getpts_aux(const char *origexpr, int nested, u8 *porttbl, int range_

current_range = origexpr;
do {
while(isspace((int) *current_range))
while(isspace((int) (unsigned char) *current_range))
current_range++; /* I don't know why I should allow spaces here, but I will */

if (change_range_type) {
Expand Down Expand Up @@ -2406,7 +2406,7 @@ static void getpts_aux(const char *origexpr, int nested, u8 *porttbl, int range_
else
rangestart = 1;
}
else if (isdigit((int) *current_range)) {
else if (isdigit((int) (unsigned char) *current_range)) {
rangestart = strtol(current_range, &endptr, 10);
if (range_type & SCAN_PROTOCOLS) {
if (rangestart < 0 || rangestart > 255)
Expand All @@ -2416,11 +2416,11 @@ static void getpts_aux(const char *origexpr, int nested, u8 *porttbl, int range_
fatal("Ports to be scanned must be between 0 and 65535 inclusive");
}
current_range = endptr;
while(isspace((int) *current_range)) current_range++;
} else if (islower((int) *current_range) || *current_range == '*' || *current_range == '?') {
while(isspace((int) (unsigned char) *current_range)) current_range++;
} else if (islower((int) (unsigned char) *current_range) || *current_range == '*' || *current_range == '?') {
i = 0;

while (*current_range && !isspace((int)*current_range) && *current_range != ',' && *current_range != ']') {
while (*current_range && !isspace((int) (unsigned char) *current_range) && *current_range != ',' && *current_range != ']') {
servmask[i++] = *(current_range++);
if (i >= ((int)sizeof(servmask)-1))
fatal("A service mask in the port/protocol specification is either malformed or too long");
Expand Down Expand Up @@ -2452,7 +2452,7 @@ static void getpts_aux(const char *origexpr, int nested, u8 *porttbl, int range_
rangeend = 255;
else
rangeend = 65535;
} else if (isdigit((int) *current_range)) {
} else if (isdigit((int) (unsigned char) *current_range)) {
rangeend = strtol(current_range, &endptr, 10);
if (range_type & SCAN_PROTOCOLS) {
if (rangeend < 0 || rangeend > 255)
Expand Down Expand Up @@ -2507,7 +2507,7 @@ static void getpts_aux(const char *origexpr, int nested, u8 *porttbl, int range_
}

/* Find the next range */
while(isspace((int) *current_range)) current_range++;
while(isspace((int) (unsigned char) *current_range)) current_range++;

if (*current_range == ']') {
if (!nested) fatal("Unexpected ] character in port/protocol specification");
Expand Down
2 changes: 1 addition & 1 deletion nmap_dns.cc
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ static u32 parse_inaddr_arpa(unsigned char *buf, int maxlen) {
maxlen -= buf[0] + 1;
if (maxlen <= 0) return 0;

for (j=1; j<=buf[0]; j++) if (!isdigit(buf[j])) return 0;
for (j=1; j<=buf[0]; j++) if (!isdigit((int) buf[j])) return 0;

ip |= atoi((char *) buf+1) << (8*i);
buf += buf[0] + 1;
Expand Down
4 changes: 2 additions & 2 deletions nmap_rpc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ static void rpc_services_init() {
ri.num_alloc *= 3;
}

while(*p && *p != '#' && !isalnum((int) *p)) p++;
while(*p && *p != '#' && !isalnum((int) (unsigned char) *p)) p++;

if (!*p || *p == '#') continue;

Expand All @@ -167,7 +167,7 @@ static void rpc_services_init() {
ri.names[ri.num_used] = cp_strdup(p);
p = tmpptr + 1;

while(*p && !isdigit((int) *p)) p++;
while(*p && !isdigit((int) (unsigned char) *p)) p++;

if (!*p)
continue;
Expand Down
12 changes: 6 additions & 6 deletions nse_binlib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ static int l_unpack(lua_State *L) /** unpack(f,s, [init]) */
{
int c=*f++;
int N=1;
if (isdigit(*f))
if (isdigit((int) (unsigned char) *f))
{
N=0;
while (isdigit(*f)) N=10*N+(*f++)-'0';
while (isdigit((int) (unsigned char) *f)) N=10*N+(*f++)-'0';
if (N==0 && c==OP_STRING) { lua_pushliteral(L,""); ++n; }
}
while (N-- && done == 0) switch (c)
Expand Down Expand Up @@ -283,10 +283,10 @@ static int l_pack(lua_State *L) /** pack(f,...) */
{
int c=*f++;
int N=1;
if (isdigit(*f))
if (isdigit((int) (unsigned char) *f))
{
N=0;
while (isdigit(*f)) N=10*N+(*f++)-'0';
while (isdigit((int) (unsigned char) *f)) N=10*N+(*f++)-'0';
}
while (N--) switch (c)
{
Expand Down Expand Up @@ -357,8 +357,8 @@ static int l_pack(lua_State *L) /** pack(f,...) */
int odd = 0;
const char *a = luaL_checklstring(L, i++, &l);
for (ii = 0; ii < l; ii++) {
if (isxdigit(a[ii])) {
if (isdigit(a[ii])) {
if (isxdigit((int) (unsigned char) a[ii])) {
if (isdigit((int) (unsigned char) a[ii])) {
sbyte += a[ii] - '0';
odd++;
} else if (a[ii] >= 'A' && a[ii] <= 'F') {
Expand Down
6 changes: 3 additions & 3 deletions nse_nsock.cc
Original file line number Diff line number Diff line change
Expand Up @@ -201,13 +201,13 @@ static std::string hexify(const unsigned char *str, size_t len)

// If more than 95% of the chars are printable, we escape unprintable chars
for (size_t i = 0; i < len; i++)
if (isprint(str[i]))
if (isprint((int) str[i]))
num++;
if ((double) num / (double) len >= 0.95)
{
for (size_t i = 0; i < len; i++)
{
if (isprint(str[i]) || isspace(str[i]))
if (isprint((int) str[i]) || isspace((int) str[i]))
ret << str[i];
else
ret << std::setw(3) << "\\" << (unsigned int) (unsigned char) str[i];
Expand All @@ -225,7 +225,7 @@ static std::string hexify(const unsigned char *str, size_t len)
else
ret << " ";
for (size_t j = i; j < i + 16 && j < len; j++)
ret.put(isgraph(str[j]) ? (unsigned char) str[j] : ' ');
ret.put(isgraph((int) str[j]) ? (unsigned char) str[j] : ' ');
ret << std::endl;
}
return ret.str();
Expand Down
22 changes: 11 additions & 11 deletions osscan.cc
Original file line number Diff line number Diff line change
Expand Up @@ -222,19 +222,19 @@ static int AVal_match(struct AVal *reference, struct AVal *fprint, struct AVal *
if (val == 0 || *endptr) { if (andexp) { testfailed=1; break; } }
else { numtrue++; if (orexp) break; }
}
} else if (*p == '<' && isxdigit((int) p[1])) {
} else if (*p == '<' && isxdigit((int) (unsigned char) p[1])) {
if (!*current_fp->value) { if (andexp) { testfailed=1; break; } }
number = strtol(p + 1, &endptr, 16);
val = strtol(current_fp->value, &endptr, 16);
if (val >= number || *endptr) { if (andexp) { testfailed=1; break; } }
else { numtrue++; if (orexp) break; }
} else if (*p == '>' && isxdigit((int) p[1])) {
} else if (*p == '>' && isxdigit((int) (unsigned char) p[1])) {
if (!*current_fp->value) { if (andexp) { testfailed=1; break; } }
number = strtol(p + 1, &endptr, 16);
val = strtol(current_fp->value, &endptr, 16);
if (val <= number || *endptr) { if (andexp) { testfailed=1; break; } }
else { numtrue++; if (orexp) break; }
} else if (((q1 = strchr(p, '-')) != NULL) && isxdigit((int) p[0]) && isxdigit((int) q1[1])) {
} else if (((q1 = strchr(p, '-')) != NULL) && isxdigit((int) (unsigned char) p[0]) && isxdigit((int) (unsigned char) q1[1])) {
if (!*current_fp->value) { if (andexp) { testfailed=1; break; } }
*q1 = '\0'; number = strtol(p, NULL, 16);
number1 = strtol(q1 + 1, NULL, 16);
Expand Down Expand Up @@ -793,9 +793,9 @@ static char *substrstrip(const char *p, const char *q) {

assert(p <= q);

while (isspace(*p))
while (isspace((int) (unsigned char) *p))
p++;
while (q > p && isspace(*(q - 1)))
while (q > p && isspace((int) (unsigned char) *(q - 1)))
q--;

s = (char *) cp_alloc(q - p + 1);
Expand Down Expand Up @@ -842,7 +842,7 @@ static void parse_classline(FingerPrint *FP, char *thisline, int lineno,
fatal("Parse error on line %d of fingerprint: %s\n", lineno, thisline);
/* OS generation is handled specially: instead of an empty string it's
supposed to be NULL. */
while (isspace(*begin))
while (isspace((int) (unsigned char) *begin))
begin++;
if (begin < end)
os_class->OS_Generation = substrstrip(begin, end);
Expand Down Expand Up @@ -884,7 +884,7 @@ FingerPrint *parse_single_fingerprint(char *fprint_orig) {
if (nextline) *nextline++ = '\0';
/* printf("Preparing to handle next line: %s\n", thisline); */

while(*thisline && isspace((int) *thisline)) thisline++;
while(*thisline && isspace((int) (unsigned char) *thisline)) thisline++;
if (!*thisline) {
fatal("Parse error on line %d of fingerprint: %s", lineno, nextline);
}
Expand All @@ -893,11 +893,11 @@ FingerPrint *parse_single_fingerprint(char *fprint_orig) {
/* Ignore a second Fingerprint line if it appears. */
if (FP->OS_name == NULL) {
p = thisline + 12;
while(*p && isspace((int) *p)) p++;
while(*p && isspace((int) (unsigned char) *p)) p++;

q = strchr(p, '\n');
if (!q) q = p + strlen(p);
while(q > p && isspace(*(--q)))
while(q > p && isspace((int) (unsigned char) *(--q)))
;

FP->OS_name = (char *) cp_alloc(q - p + 2);
Expand Down Expand Up @@ -1029,12 +1029,12 @@ while(fgets(line, sizeof(line), fp)) {
} else {
DB->prints[numrecords] = current;
p = line + 12;
while(*p && isspace((int) *p)) p++;
while(*p && isspace((int) (unsigned char) *p)) p++;

q = strpbrk(p, "\n#");
if (!p) fatal("Parse error on line %d of fingerprint: %s", lineno, line);

while(isspace(*(--q)))
while(isspace((int) (unsigned char) *(--q)))
;

if (q < p) fatal("Parse error on line %d of fingerprint: %s", lineno, line);
Expand Down
2 changes: 1 addition & 1 deletion output.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ static void skid_output(char *s)
case 'O': s[i]='0'; break;
case 's':
case 'S':
if (s[i+1] && !isalnum((int) s[i+1]))
if (s[i+1] && !isalnum((int) (unsigned char) s[i+1]))
s[i] = 'z';
else s[i] = '$';
break;
Expand Down
2 changes: 1 addition & 1 deletion protocols.cc
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ static int nmap_protocols_init() {
while(fgets(line, sizeof(line), fp)) {
lineno++;
p = line;
while(*p && isspace((int) *p))
while(*p && isspace((int) (unsigned char) *p))
p++;
if (*p == '#')
continue;
Expand Down
Loading

0 comments on commit 9c3c689

Please sign in to comment.