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:
+8
-2
@@ -344,8 +344,14 @@ static gcry_error_t _gcry_cipher_crypt (gcry_cipher_hd_t h,
|
||||
src ? src:(const unsigned char *)in, (unsigned char *)out);
|
||||
break;
|
||||
case GCRY_CIPHER_MODE_GCM:
|
||||
if(encrypt) return MBEDTLS_ERR_GCM_NOT_SUPPORT;
|
||||
if(!( h->s_key && h->s_auth && h->s_iv && !h->s_crypt_ok)) return MBEDTLS_ERR_GCM_MISSING_KEY;
|
||||
if(encrypt) {
|
||||
ndpi_free(src);
|
||||
return MBEDTLS_ERR_GCM_NOT_SUPPORT;
|
||||
}
|
||||
if(!( h->s_key && h->s_auth && h->s_iv && !h->s_crypt_ok)) {
|
||||
ndpi_free(src);
|
||||
return MBEDTLS_ERR_GCM_MISSING_KEY;
|
||||
}
|
||||
h->taglen = 16;
|
||||
rv = mbedtls_gcm_crypt_and_tag(h->ctx.gcm,
|
||||
MBEDTLS_GCM_DECRYPT,
|
||||
|
||||
+2
-5
@@ -40,7 +40,6 @@
|
||||
*/
|
||||
|
||||
#include <assert.h> /* assert */
|
||||
#include <ctype.h> /* isdigit */
|
||||
#include <errno.h> /* errno */
|
||||
#include <math.h> /* sin */
|
||||
#include <stddef.h> /* NULL */
|
||||
@@ -76,8 +75,6 @@ static u_char* ndpi_prefix_tochar (ndpi_prefix_t * prefix)
|
||||
if(family == AF_INET) return ((u_char *) & prefix->add.sin);
|
||||
else if(family == AF_INET6) return ((u_char *) & prefix->add.sin6);
|
||||
else /* if(family == AF_MAC) */ return ((u_char *) & prefix->add.mac);
|
||||
|
||||
return ((u_char *) & prefix->add.sin);
|
||||
}
|
||||
|
||||
static int ndpi_comp_with_mask (void *addr, void *dest, u_int mask) {
|
||||
@@ -103,7 +100,7 @@ static int ndpi_my_inet_pton (int af, const char *src, void *dst)
|
||||
int c, val;
|
||||
|
||||
c = *src++;
|
||||
if(!isdigit (c))
|
||||
if(!ndpi_isdigit (c))
|
||||
return (-1);
|
||||
val = 0;
|
||||
do {
|
||||
@@ -111,7 +108,7 @@ static int ndpi_my_inet_pton (int af, const char *src, void *dst)
|
||||
if(val > 255)
|
||||
return (0);
|
||||
c = *src++;
|
||||
} while (c && isdigit (c));
|
||||
} while (c && ndpi_isdigit (c));
|
||||
xp[i] = (u_char)val;
|
||||
if(c == '\0')
|
||||
break;
|
||||
|
||||
Vendored
+4
-4
@@ -130,8 +130,8 @@ strptime(const char* buf, const char* fmt, struct tm* tm)
|
||||
alt_format = 0;
|
||||
|
||||
/* Eat up white-space. */
|
||||
if (isspace(c)) {
|
||||
while (isspace(*bp))
|
||||
if (ndpi_isspace(c)) {
|
||||
while (ndpi_isspace(*bp))
|
||||
bp++;
|
||||
|
||||
fmt++;
|
||||
@@ -397,7 +397,7 @@ strptime(const char* buf, const char* fmt, struct tm* tm)
|
||||
case 'n': /* Any kind of white-space. */
|
||||
case 't':
|
||||
LEGAL_ALT(0);
|
||||
while (isspace(*bp))
|
||||
while (ndpi_isspace(*bp))
|
||||
bp++;
|
||||
break;
|
||||
|
||||
@@ -437,4 +437,4 @@ conv_num(const char** buf, int* dest, int llim, int ulim)
|
||||
return (1);
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user