Fixed a few warnings

Warnings were found with GCC, Clang and Cppcheck.
This commit is contained in:
wiire-a 2017-11-13 12:23:44 +01:00
parent 81301b7e71
commit 6bdf8e8f37
5 changed files with 43 additions and 50 deletions

View File

@ -159,7 +159,7 @@ static void init_crack_jobs(struct global *wps) {
memset(job_control.randr_enonce, 0, sizeof(job_control.randr_enonce));
/* Converting enrollee nonce to the sequence may be generated by current random function */
int i, j = 0;
for (int i = 0; i < 4; i++) {
for (i = 0; i < 4; i++) {
job_control.randr_enonce[i] |= wps->e_nonce[j++];
job_control.randr_enonce[i] <<= 8;
job_control.randr_enonce[i] |= wps->e_nonce[j++];
@ -523,7 +523,7 @@ usage_err:
printf("\n Pixiewps %s\n", SHORT_VERSION);
if (wps->verbosity > 1) {
printf("\n [*] Mode: %u (%s)", RTL819x, p_mode_name[RTL819x]);
printf("\n [*] Mode: %d (%s)", RTL819x, p_mode_name[RTL819x]);
}
vtag_t *vtag;
if (wps->verbosity > 2) {
@ -532,24 +532,24 @@ usage_err:
printf("\n [*] AuthKey: "); byte_array_print(wps->authkey, WPS_AUTHKEY_LEN);
printf("\n [*] EMSK: "); byte_array_print(wps->emsk, WPS_EMSK_LEN);
printf("\n [*] KeyWrapKey: "); byte_array_print(wps->wrapkey, WPS_KEYWRAPKEY_LEN);
if (vtag = find_vtag(decrypted7, wps->m7_encr_len - 16, WPS_TAG_KEYWRAP_AUTH, WPS_TAG_KEYWRAP_AUTH_LEN)) {
if ((vtag = find_vtag(decrypted7, wps->m7_encr_len - 16, WPS_TAG_KEYWRAP_AUTH, WPS_TAG_KEYWRAP_AUTH_LEN))) {
memcpy(buffer, vtag->data, WPS_TAG_KEYWRAP_AUTH_LEN);
printf("\n [*] KeyWrap Authenticator: "); byte_array_print(buffer, WPS_TAG_KEYWRAP_AUTH_LEN);
}
}
if (vtag = find_vtag(decrypted5, wps->m5_encr_len - 16, WPS_TAG_E_SNONCE_1, WPS_NONCE_LEN)) {
if ((vtag = find_vtag(decrypted5, wps->m5_encr_len - 16, WPS_TAG_E_SNONCE_1, WPS_NONCE_LEN))) {
printf("\n [*] ES-1: "); byte_array_print(vtag->data, WPS_NONCE_LEN);
}
if (vtag = find_vtag(decrypted7, wps->m7_encr_len - 16, WPS_TAG_E_SNONCE_2, WPS_NONCE_LEN)) {
if ((vtag = find_vtag(decrypted7, wps->m7_encr_len - 16, WPS_TAG_E_SNONCE_2, WPS_NONCE_LEN))) {
printf("\n [*] ES-2: "); byte_array_print(vtag->data, WPS_NONCE_LEN);
}
if (vtag = find_vtag(decrypted7, wps->m7_encr_len - 16, WPS_TAG_SSID, 0)) {
if ((vtag = find_vtag(decrypted7, wps->m7_encr_len - 16, WPS_TAG_SSID, 0))) {
int tag_size = be16_to_h(vtag->len);
memcpy(buffer, vtag->data, tag_size);
buffer[tag_size] = '\0';
printf("\n [*] SSID: %s", buffer);
}
if (vtag = find_vtag(decrypted7, wps->m7_encr_len - 16, WPS_TAG_NET_KEY, 0)) {
if ((vtag = find_vtag(decrypted7, wps->m7_encr_len - 16, WPS_TAG_NET_KEY, 0))) {
int tag_size = be16_to_h(vtag->len);
memcpy(buffer, vtag->data, tag_size);
buffer[tag_size] = '\0';
@ -715,9 +715,12 @@ usage_err:
/* KDK = HMAC-SHA-256{DHKey}(Enrollee nonce || Enrollee MAC || Registrar nonce) */
hmac_sha256(wps->dhkey, WPS_HASH_LEN, buffer, WPS_NONCE_LEN * 2 + WPS_BSSID_LEN, wps->kdk);
buffer = realloc(buffer, WPS_HASH_LEN * 3);
if (!buffer)
uint8_t *nbuffer = realloc(buffer, WPS_HASH_LEN * 3);
if (!nbuffer) {
free(buffer);
goto memory_err;
}
buffer = nbuffer;
/* Key derivation function */
kdf(wps->kdk, buffer);
@ -776,7 +779,7 @@ usage_err:
uint32_t s2_seed = 0;
/* Main loop */
while (!found_p_mode && p_mode[k] != NONE && k < MODE_LEN) {
while (!found_p_mode && k < MODE_LEN && p_mode[k] != NONE) {
/* 1 */
if (p_mode[k] == RT) {
@ -867,7 +870,7 @@ usage_err:
wps->warning = calloc(256, 1);
if (!wps->warning)
goto memory_err;
snprintf(wps->warning, 256, " [!] Small DH keys is not supported for mode %u!\n\n", RTL819x);
snprintf(wps->warning, 256, " [!] Small DH keys is not supported for mode %d!\n\n", RTL819x);
}
} else {
@ -1266,7 +1269,6 @@ int int_pow(int a, int exp) {
/* PIN cracking attempt */
uint_fast8_t crack(struct global *g, char *pin) {
struct global *wps = g;
unsigned int i, j, count;
unsigned int first_half = 0;
unsigned int second_half = 0;
uint8_t s_pin[4];
@ -1278,16 +1280,18 @@ uint_fast8_t crack(struct global *g, char *pin) {
return MEM_ERROR;
uint8_t *result = malloc(WPS_HASH_LEN);
if (!result)
if (!result) {
free(buffer);
return MEM_ERROR;
}
if (wps->anylength) {
/* Brute-force entire pin space */
for (i = 0; i < 5; i++)
{
first_half = 0;
count = int_pow(10, i);
/* Brute-force entire pin space */
for (unsigned int i = 0; i < 5; i++) {
unsigned int count = int_pow(10, i);
first_half = 0;
while (first_half < count) {
uint_to_char_array(first_half, i, s_pin);
hmac_sha256(wps->authkey, WPS_AUTHKEY_LEN, s_pin, i, wps->psk1);
@ -1313,11 +1317,10 @@ uint_fast8_t crack(struct global *g, char *pin) {
}
if (first_half < count) {
for (j = 0; j < 5; j++)
{
second_half = 0;
for (unsigned int j = 0; j < 5; j++) {
count = int_pow(10, j);
second_half = 0;
while (second_half < count) {
uint_to_char_array(second_half, j, s_pin);
hmac_sha256(wps->authkey, WPS_AUTHKEY_LEN, s_pin, j, wps->psk2);
@ -1400,13 +1403,11 @@ uint_fast8_t crack(struct global *g, char *pin) {
}
if (first_half < 10000) { /* First half found */
uint_fast8_t checksum_digit;
unsigned int c_second_half;
/* Testing with checksum digit */
while (second_half < 1000) {
checksum_digit = wps_pin_checksum(first_half * 1000 + second_half);
c_second_half = second_half * 10 + checksum_digit;
unsigned int checksum_digit = wps_pin_checksum(first_half * 1000 + second_half);
unsigned int c_second_half = second_half * 10 + checksum_digit;
uint_to_char_array(c_second_half, 4, s_pin);
hmac_sha256(wps->authkey, WPS_AUTHKEY_LEN, s_pin, 4, wps->psk2);
memcpy(buffer, wps->e_s2, WPS_SECRET_NONCE_LEN);

View File

@ -114,7 +114,7 @@ struct global {
uint8_t mode_auto;
uint8_t bruteforce;
uint8_t anylength;
unsigned jobs;
int jobs;
int verbosity;
char *error;
char *warning;
@ -263,7 +263,7 @@ static inline uint_fast8_t parse_mode(char *list, uint_fast8_t *dst, const uint8
/* Checks if passed mode is selected */
static inline uint_fast8_t is_mode_selected(const uint_fast8_t mode) {
for (uint_fast8_t i = 0; p_mode[i] != NONE && i < MODE_LEN; i++) {
for (uint_fast8_t i = 0; i < MODE_LEN && p_mode[i] != NONE; i++) {
if (p_mode[i] == mode)
return 1;
}

View File

@ -130,9 +130,6 @@ void m_srandom_r(unsigned int seed, struct m_random_data *buf)
Returns a pointer to the old state. */
void m_initstate_r(unsigned int seed, char *arg_state, struct m_random_data *buf)
{
int type;
int degree;
int separation;
int32_t *state = &((int32_t *)arg_state)[1]; /* First location */
/* Must set END_PTR before srandom */

View File

@ -29,15 +29,14 @@
/* Converts an hex string to a byte array */
unsigned int hex_string_to_byte_array(char *in, uint8_t *out, const unsigned int n_len) {
uint_fast8_t o;
unsigned int len = strlen(in);
unsigned int b_len = n_len * 2 + n_len - 1;
if (len != n_len * 2 && len != b_len)
return 1;
for (unsigned int i = 0; i < n_len; i++) {
o = 0;
for (uint_fast8_t j = 0; j < 2; j++) {
unsigned char o = 0;
for (unsigned char j = 0; j < 2; j++) {
o <<= 4;
if (*in >= 'A' && *in <= 'F')
*in += 'a'-'A';
@ -70,12 +69,14 @@ unsigned int hex_string_to_byte_array_max(char *in, uint8_t *out, const unsigned
if (len > 2)
if (in[2] == ':' || in[2] == '-' || in[2] == ' ')
separator = 1;
if (separator)
if (separator) {
if ((len + 1) / 3 > max_len)
return 1;
else
}
else {
if (len / 2 > max_len)
return 1;
}
for (unsigned int i = 0; i < max_len; i++) {
o = 0;
@ -189,7 +190,7 @@ unsigned int get_unix_datetime(char *s, time_t *datetime) {
if (get_int(s_month, &month) || get_int(s_year, &year))
return 1;
if ((year < 1970 && year > 2037) || (month < 1 && month > 12))
if (year < 1970 || year > 2038 || month < 1 || month > 12)
return 1;
} else {
return 1;
@ -238,16 +239,12 @@ void byte_array_print(const uint8_t *buffer, const unsigned int length) {
uint32_t h32_to_be(const uint32_t num) {
uint32_t tmp = num;
uint32_t res;
uint32_t b0, b1, b2, b3;
unsigned int i = 1;
char *p = (char *) &i;
if (p[0] == 1) { /* LE */
b0 = (tmp & 0x000000ff) << 24;
b1 = (tmp & 0x0000ff00) << 8;
b2 = (tmp & 0x00ff0000) >> 8;
b3 = (tmp & 0xff000000) >> 24;
res = b0 | b1 | b2 | b3;
res = ((tmp & 0x000000ff) << 24) | ((tmp & 0x0000ff00) << 8) |
((tmp & 0x00ff0000) >> 8) | ((tmp & 0xff000000) >> 24);
} else { /* BE */
res = num;
}
@ -258,14 +255,11 @@ uint32_t h32_to_be(const uint32_t num) {
uint16_t be16_to_h(const uint16_t num) {
uint16_t tmp = num;
uint16_t res;
uint16_t b0, b1;
unsigned int i = 1;
char *p = (char *) &i;
if (p[0] == 1) { /* LE */
b0 = (tmp & 0x000000ff) << 8;
b1 = (tmp & 0x0000ff00) >> 8;
res = b0 | b1;
res = ((tmp & 0x000000ff) << 8) | ((tmp & 0x0000ff00) >> 8);
} else { /* BE */
res = num;
}

View File

@ -64,13 +64,14 @@ struct ie_vtag {
typedef struct ie_vtag vtag_t;
#define VTAG_SIZE (sizeof(vtag_t))
vtag_t *find_vtag(void *vtagp, int vtagl, uint8_t *vid, int vlen) {
vtag_t *vtag = (vtag_t*)vtagp;
vtag_t *find_vtag(void *vtagp, int vtagl, void *vidp, int vlen) {
uint8_t *vid = vidp;
vtag_t *vtag = vtagp;
while (0 < vtagl) {
if (vid && memcmp(vid, &vtag->id, 2) != 0)
goto next_vtag;
if (!vlen || be16_to_h(vtag->len) == vlen);
return vtag;
if (!vlen || be16_to_h(vtag->len) == vlen)
return vtag;
next_vtag:
vtagl -= be16_to_h(vtag->len) + VTAG_SIZE;