Fix some warnings reported by CODESonar (#2227)
Remove some unreached/duplicated code. Add error checking for `atoi()` calls. About `isdigit()` and similar functions. The warning reported is: ``` Negative Character Value help isdigit() is invoked here with an argument of signed type char, but only has defined behavior for int arguments that are either representable as unsigned char or equal to the value of macro EOF(-1). Casting the argument to unsigned char will avoid the undefined behavior. In a number of libc implementations, isdigit() is implemented using lookup tables (arrays): passing in a negative value can result in a read underrun. ``` Switching to our macros fix that. Add a check to `check_symbols.sh` to avoid using the original functions from libc.
This commit is contained in:
@@ -129,7 +129,7 @@ int ndpi_analyze_payload(struct ndpi_flow_info *flow,
|
||||
#ifdef DEBUG_PAYLOAD
|
||||
u_int16_t i;
|
||||
for(i=0; i<payload_len; i++)
|
||||
printf("%c", isprint(payload[i]) ? payload[i] : '.');
|
||||
printf("%c", ndpi_isprint(payload[i]) ? payload[i] : '.');
|
||||
printf("\n");
|
||||
#endif
|
||||
|
||||
@@ -247,7 +247,7 @@ static void print_payload_stat(struct payload_stats *p, FILE *out) {
|
||||
fprintf(out, "\t[");
|
||||
|
||||
for(i=0; i<p->pattern_len; i++) {
|
||||
fprintf(out, "%c", isprint(p->pattern[i]) ? p->pattern[i] : '.');
|
||||
fprintf(out, "%c", ndpi_isprint(p->pattern[i]) ? p->pattern[i] : '.');
|
||||
}
|
||||
|
||||
fprintf(out, "]");
|
||||
@@ -255,7 +255,7 @@ static void print_payload_stat(struct payload_stats *p, FILE *out) {
|
||||
fprintf(out, "[");
|
||||
|
||||
for(i=0; i<p->pattern_len; i++) {
|
||||
fprintf(out, "%s%02X", (i > 0) ? " " : "", isprint(p->pattern[i]) ? p->pattern[i] : '.');
|
||||
fprintf(out, "%s%02X", (i > 0) ? " " : "", ndpi_isprint(p->pattern[i]) ? p->pattern[i] : '.');
|
||||
}
|
||||
|
||||
fprintf(out, "]");
|
||||
|
||||
Reference in New Issue
Block a user