Skip to content

Commit

Permalink
chore: resolve PVS-Studio warnings
Browse files Browse the repository at this point in the history
Signed-off-by: Joseph Benden <joe@benden.us>
  • Loading branch information
jbenden committed Aug 19, 2021
1 parent 255a85f commit 8f9e88e
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 37 deletions.
7 changes: 4 additions & 3 deletions include/aircrack-ng/ce-wpa/pseudo_intrinsics.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ typedef uint64x2_t vtype64;
#define vor vorrq_u32
#define vorn vornq_u32
#define vroti_epi32(x, i) \
(i > 0 ? vsliq_n_u32(vshrq_n_u32(x, (32 - ((i)&31))&31), x, (i)&31) \
: vsriq_n_u32(vshlq_n_u32(x, (32 + ((i)&31))&31), x, -(i)&31))
(i > 0 ? vsliq_n_u32(vshrq_n_u32(x, (32 - ((i) &31)) & 31), x, (i) &31) \
: vsriq_n_u32(vshlq_n_u32(x, (32 + ((i) &31)) & 31), x, -(i) &31))
#define vroti_epi64(x, i) \
(i > 0 ? (vtype) vsliq_n_u64( \
vshrq_n_u64((vtype64)(x), 64 - (i)), (vtype64)(x), i) \
Expand Down Expand Up @@ -370,7 +370,8 @@ typedef __m512i vtype;

/* MIC lacks some intrinsics in AVX512F, thus needing emulation. */
#if __MIC__
#define _mm512_set1_epi8(x) _mm512_set1_epi32(x | x << 8 | x << 16 | x << 24)
#define _mm512_set1_epi8(x) \
_mm512_set1_epi32((x) | (x) << 8 | (x) << 16 | (x) << 24)

static inline __m512i _mm512_loadu_si512(void const * addr)
{
Expand Down
2 changes: 1 addition & 1 deletion lib/osdep/linux.c
Original file line number Diff line number Diff line change
Expand Up @@ -1958,7 +1958,7 @@ static int do_linux_open(struct wif * wi, char * iface)

/* check if newer athXraw interface available */

if ((strlen(iface) >= 4 && strlen(iface) <= 6)
if ((strlen(iface) >= 4 && strlen(iface) <= 6) //-V804
&& memcmp(iface, "ath", 3) == 0)
{
dev->drivertype = DT_MADWIFI;
Expand Down
2 changes: 1 addition & 1 deletion src/airbase-ng/airbase-ng.c
Original file line number Diff line number Diff line change
Expand Up @@ -2844,7 +2844,7 @@ static THREAD_ENTRY(beacon_thread)
if (!essid_len)
{
strncpy((char *) essid, "default", sizeof(essid) - 1);
essid_len = strlen("default");
essid_len = strlen("default"); //-V814
}

beacon_len = 0;
Expand Down
7 changes: 5 additions & 2 deletions src/aireplay-ng/aireplay-ng.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
#include <time.h>
#include <getopt.h>
#include <assert.h>
#include <math.h>

#include <fcntl.h>
#include <ctype.h>
Expand Down Expand Up @@ -574,7 +575,7 @@ static int do_attack_deauth(void)
static int do_attack_fake_auth(void)
{
time_t tt, tr;
struct timeval tv, tv2, tv3;
struct timeval tv, tv2 = {0}, tv3;

fd_set rfds;
int i, n, state, caplen, z;
Expand Down Expand Up @@ -4033,7 +4034,9 @@ static int do_attack_chopchop(void)
float const delta_tt = (float) (time(NULL) - tt);
printf("\nCompleted in %lds (%0.2f bytes/s)\n\n",
(long) delta_tt,
(delta_tt != 0 ? (float) ((pkh.caplen - 6 - 24) / delta_tt) : 0.f));
(fabsf(delta_tt) >= __FLT_EPSILON__
? (float) ((pkh.caplen - 6 - 24) / delta_tt)
: 0.f));

return (0);
}
Expand Down
34 changes: 20 additions & 14 deletions src/airodump-ng/airodump-ng.c
Original file line number Diff line number Diff line change
Expand Up @@ -4278,6 +4278,7 @@ get_manufacturer(unsigned char mac0, unsigned char mac1, unsigned char mac2)
unsigned char b[2];
unsigned char c[2];
int found = 0;
size_t oui_len;

if ((manuf = (char *) calloc(1, MANUF_SIZE * sizeof(char))) == NULL)
{
Expand All @@ -4286,6 +4287,7 @@ get_manufacturer(unsigned char mac0, unsigned char mac1, unsigned char mac2)
}

snprintf(oui, sizeof(oui), "%02X:%02X:%02X", mac0, mac1, mac2);
oui_len = strlen(oui);

if (lopt.manufList != NULL)
{
Expand Down Expand Up @@ -4338,7 +4340,7 @@ get_manufacturer(unsigned char mac0, unsigned char mac1, unsigned char mac2)
b[1],
c[0],
c[1]);
found = !memcmp(temp, oui, strlen(oui));
found = !memcmp(temp, oui, oui_len);
if (found)
{
manuf_str = get_manufacturer_from_string(buffer);
Expand Down Expand Up @@ -5234,8 +5236,8 @@ static inline int invalid_frequency(int freq)

static int getchannels(const char * optarg)
{
unsigned int i = 0, chan_cur = 0, chan_first = 0, chan_last = 0,
chan_max = 128, chan_remain = 0;
size_t i = 0, chan_cur = 0, chan_first = 0, chan_last = 0, chan_max = 128,
chan_remain = 0;
char *optchan = NULL, *optc;
char * token = NULL;
int * tmp_channels;
Expand All @@ -5258,14 +5260,16 @@ static int getchannels(const char * optarg)
// split string in tokens, separated by ','
while ((token = strsep(&optchan, ",")) != NULL)
{
const size_t token_len = strlen(token);

// range defined?
if (strchr(token, '-') != NULL)
{
// only 1 '-' ?
if (strchr(token, '-') == strrchr(token, '-'))
{
// are there any illegal characters?
for (i = 0; i < strlen(token); i++)
for (i = 0; i < token_len; i++)
{
if (((token[i] < '0') || (token[i] > '9'))
&& (token[i] != '-'))
Expand All @@ -5276,7 +5280,7 @@ static int getchannels(const char * optarg)
}
}

if (sscanf(token, "%u-%u", &chan_first, &chan_last) != EOF)
if (sscanf(token, "%zu-%zu", &chan_first, &chan_last) != EOF)
{
if (chan_first > chan_last)
{
Expand Down Expand Up @@ -5310,7 +5314,7 @@ static int getchannels(const char * optarg)
else
{
// are there any illegal characters?
for (i = 0; i < strlen(token); i++)
for (i = 0; i < token_len; i++)
{
if ((token[i] < '0') || (token[i] > '9'))
{
Expand All @@ -5320,7 +5324,7 @@ static int getchannels(const char * optarg)
}
}

if (sscanf(token, "%u", &chan_cur) != EOF)
if (sscanf(token, "%zu", &chan_cur) != EOF)
{
if ((!invalid_channel(chan_cur)) && (chan_remain > 0))
{
Expand Down Expand Up @@ -5362,8 +5366,8 @@ static int getchannels(const char * optarg)

static int getfrequencies(const char * optarg)
{
unsigned int i = 0, freq_cur = 0, freq_first = 0, freq_last = 0,
freq_max = 10000, freq_remain = 0;
size_t i = 0, freq_cur = 0, freq_first = 0, freq_last = 0, freq_max = 10000,
freq_remain = 0;
char *optfreq = NULL, *optc;
char * token = NULL;
int * tmp_frequencies;
Expand All @@ -5386,14 +5390,16 @@ static int getfrequencies(const char * optarg)
// split string in tokens, separated by ','
while ((token = strsep(&optfreq, ",")) != NULL)
{
const size_t token_len = strlen(token);

// range defined?
if (strchr(token, '-') != NULL)
{
// only 1 '-' ?
if (strchr(token, '-') == strrchr(token, '-'))
{
// are there any illegal characters?
for (i = 0; i < strlen(token); i++)
for (i = 0; i < token_len; i++)
{
if ((token[i] < '0' || token[i] > '9') && (token[i] != '-'))
{
Expand All @@ -5403,7 +5409,7 @@ static int getfrequencies(const char * optarg)
}
}

if (sscanf(token, "%u-%u", &freq_first, &freq_last) != EOF)
if (sscanf(token, "%zu-%zu", &freq_first, &freq_last) != EOF)
{
if (freq_first > freq_last)
{
Expand Down Expand Up @@ -5437,7 +5443,7 @@ static int getfrequencies(const char * optarg)
else
{
// are there any illegal characters?
for (i = 0; i < strlen(token); i++)
for (i = 0; i < token_len; i++)
{
if ((token[i] < '0') || (token[i] > '9'))
{
Expand All @@ -5447,7 +5453,7 @@ static int getfrequencies(const char * optarg)
}
}

if (sscanf(token, "%u", &freq_cur) != EOF)
if (sscanf(token, "%zu", &freq_cur) != EOF)
{
if ((!invalid_frequency(freq_cur)) && (freq_remain > 0))
{
Expand Down Expand Up @@ -6199,7 +6205,7 @@ int main(int argc, char * argv[])
}
freq[0] = freq[1] = 0;

for (i = 0; i < (int) strlen(optarg); i++)
for (i = 0; i < (int) strlen(optarg); i++) //-V814
{
if (optarg[i] == 'a')
freq[1] = 1;
Expand Down
28 changes: 18 additions & 10 deletions src/airodump-ng/dump_write.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,12 @@ int dump_write_csv(struct AP_info * ap_1st,

if (ap_cur->key != NULL)
{
for (i = 0; i < (int) strlen(ap_cur->key); i++)
const int key_len = strlen(ap_cur->key);

for (i = 0; i < key_len; i++)
{
fprintf(opt.f_txt, "%02X", ap_cur->key[i]);
if (i < (int) (strlen(ap_cur->key) - 1))
fprintf(opt.f_txt, ":");
if (i < (key_len - 1)) fprintf(opt.f_txt, ":");
}
}

Expand Down Expand Up @@ -623,17 +624,18 @@ char * get_manufacturer_from_string(char * buffer)
// Did we stop at the manufacturer
if (*buffer_manuf != '\0')
{
const int buffer_manuf_len_minus_1 = strlen(buffer_manuf);

// First make sure there's no end of line
if (buffer_manuf[strlen(buffer_manuf) - 1] == '\n'
|| buffer_manuf[strlen(buffer_manuf) - 1] == '\r')
if (buffer_manuf[buffer_manuf_len_minus_1] == '\n'
|| buffer_manuf[buffer_manuf_len_minus_1] == '\r')
{
buffer_manuf[strlen(buffer_manuf) - 1] = '\0';
if (*buffer_manuf != '\0'
&& (buffer_manuf[strlen(buffer_manuf) - 1] == '\n'
|| buffer[strlen(buffer_manuf) - 1] == '\r'))
buffer_manuf[buffer_manuf_len_minus_1] = '\0';
if (buffer_manuf_len_minus_1 >= 1
&& (buffer_manuf[buffer_manuf_len_minus_1 - 1] == '\n'
|| buffer[buffer_manuf_len_minus_1 - 1] == '\r'))
{
buffer_manuf[strlen(buffer_manuf) - 1] = '\0';
buffer_manuf[buffer_manuf_len_minus_1 - 1] = '\0';
}
}
if (*buffer_manuf != '\0')
Expand Down Expand Up @@ -684,9 +686,11 @@ static int dump_write_kismet_netxml_client_info(struct ST_info * client,
|| memcmp(client->base->bssid, BROADCAST, 6) == 0);

strncpy(first_time, ctime(&client->tinit), TIME_STR_LENGTH - 1);
ENSURE(strlen(first_time) >= 1);
first_time[strlen(first_time) - 1] = 0; // remove new line

strncpy(last_time, ctime(&client->tlast), TIME_STR_LENGTH - 1);
ENSURE(strlen(last_time) >= 1);
last_time[strlen(last_time) - 1] = 0; // remove new line

fprintf(opt.f_kis_xml,
Expand Down Expand Up @@ -920,9 +924,11 @@ int dump_write_kismet_netxml(struct AP_info * ap_1st,

++network_number; // Network Number
strncpy(first_time, ctime(&ap_cur->tinit), TIME_STR_LENGTH - 1);
ENSURE(strlen(first_time) >= 1);
first_time[strlen(first_time) - 1] = 0; // remove new line

strncpy(last_time, ctime(&ap_cur->tlast), TIME_STR_LENGTH - 1);
ENSURE(strlen(last_time) >= 1);
last_time[strlen(last_time) - 1] = 0; // remove new line

fprintf(opt.f_kis_xml,
Expand Down Expand Up @@ -1184,9 +1190,11 @@ int dump_write_kismet_netxml(struct AP_info * ap_1st,

/* Write new network information */
strncpy(first_time, ctime(&st_cur->tinit), TIME_STR_LENGTH - 1);
ENSURE(strlen(first_time) >= 1);
first_time[strlen(first_time) - 1] = 0; // remove new line

strncpy(last_time, ctime(&st_cur->tlast), TIME_STR_LENGTH - 1);
ENSURE(strlen(last_time) >= 1);
last_time[strlen(last_time) - 1] = 0; // remove new line

fprintf(opt.f_kis_xml,
Expand Down
12 changes: 8 additions & 4 deletions src/airolib-ng/airolib-ng.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,9 +604,11 @@ static void batch_process(sqlite3 * db)

// Verify an ESSID. Returns 1 if ESSID is invalid.
// TODO More things to verify? Invalid chars?
static int verify_essid(char * essid)
static int verify_essid(char * const essid)
{
return (essid == NULL || strlen(essid) < 1 || strlen(essid) > 32);
const size_t essid_len = strlen(essid);

return (essid == NULL || essid_len < 1 || essid_len > 32);
}

// sql function which checks a given ESSID
Expand All @@ -623,9 +625,11 @@ sql_verify_essid(sqlite3_context * context, int argc, sqlite3_value ** values)
sqlite3_result_int(context, verify_essid(essid));
}

static int verify_passwd(char * passwd)
static int verify_passwd(char * const passwd)
{
return (passwd == NULL || strlen(passwd) < 8 || strlen(passwd) > 63);
const size_t passwd_len = strlen(passwd);

return (passwd == NULL || passwd_len < 8 || passwd_len > 63);
}

static void
Expand Down
4 changes: 2 additions & 2 deletions src/tkiptun-ng/tkiptun-ng.c
Original file line number Diff line number Diff line change
Expand Up @@ -2135,7 +2135,7 @@ static int do_attack_tkipchop(unsigned char * src_packet, int src_packet_len)
return (1);
}

n = pkh.caplen + 8 - 26 - 8;
n = pkh.caplen - 26;

if (fwrite(chopped + 26 + 8, n, 1, f_cap_out) != 1)
{
Expand Down Expand Up @@ -2562,7 +2562,7 @@ int main(int argc, char * argv[])
case 'p':

memset(lopt.psk, 0, sizeof(lopt.psk));
if (strlen(optarg) < 8 || strlen(optarg) > 63)
if (strlen(optarg) < 8 || strlen(optarg) > 63) //-V804
{
printf("PSK with invalid length specified [8-64].\n");
printf("\"%s --help\" for help.\n", argv[0]);
Expand Down

0 comments on commit 8f9e88e

Please sign in to comment.