]> git.zerfleddert.de Git - proxmark3-svn/blobdiff - client/cmdhfmfhard.c
FIX: 'hf mf hardnested' @matrix https://github.com/iceman1001/proxmark3/commit/e0828...
[proxmark3-svn] / client / cmdhfmfhard.c
index dcf454c58078bb21f53c870bd54d140e0b571685..1f739dc46c3babf9af6d603659b017360745efcc 100644 (file)
@@ -280,15 +280,16 @@ static float sum_probability(uint16_t K, uint16_t n, uint16_t k)
        if (k > K || p_K[K] == 0.0) return 0.0;
 
        double p_T_is_k_when_S_is_K = p_hypergeometric(N, K, n, k);
+       if (p_T_is_k_when_S_is_K == 0.0) return 0.0;
+
        double p_S_is_K = p_K[K];
        double p_T_is_k = 0;
        for (uint16_t i = 0; i <= 256; i++) {
                if (p_K[i] != 0.0) {
-                       double tmp = p_hypergeometric(N, i, n, k);
-                       if (tmp != 0.0)
-                               p_T_is_k += p_K[i] * tmp;
+                       p_T_is_k += p_K[i] * p_hypergeometric(N, i, n, k);
                }
        }
+       if (p_T_is_k == 0.0) return 0.0;
        return(p_T_is_k_when_S_is_K * p_S_is_K / p_T_is_k);
 }
 
@@ -1157,7 +1158,7 @@ static int add_matching_states(statelist_t *candidates, uint16_t part_sum_a0, ui
        for (uint32_t *p1 = partial_statelist[part_sum_a0].states[odd_even]; *p1 != END_OF_LIST_MARKER; p1++) {
                uint32_t search_mask = 0x000ffff0;
                uint32_t *p2 = find_first_state((*p1 << 4), search_mask, &partial_statelist[part_sum_a8], odd_even);
-               if (p2 != NULL) {
+               if (p1 != NULL && p2 != NULL) {
                        while (((*p1 << 4) & search_mask) == (*p2 & search_mask) && *p2 != END_OF_LIST_MARKER) {
                                if ((nonces[best_first_bytes[0]].BitFlip[odd_even] && find_first_state((*p1 << 4) | *p2, 0x000fffff, &statelist_bitflip, 0))
                                        || !nonces[best_first_bytes[0]].BitFlip[odd_even]) {
@@ -1195,6 +1196,8 @@ static statelist_t *add_more_candidates(statelist_t *current_candidates)
        } else {
                new_candidates = current_candidates->next = (statelist_t *)malloc(sizeof(statelist_t));
        }
+       if (!new_candidates) return NULL;
+
        new_candidates->next = NULL;
        new_candidates->len[ODD_STATE] = 0;
        new_candidates->len[EVEN_STATE] = 0;
@@ -1287,7 +1290,7 @@ static bool generate_candidates(uint16_t sum_a0, uint16_t sum_a8)
                                        for (uint16_t s = 0; s <= 16; s += 2) {
                                                if (r*(16-s) + (16-r)*s == sum_a8) {
                                                        current_candidates = add_more_candidates(current_candidates);
-                                                       if (current_candidates) {
+                                                       if (current_candidates != NULL) {
                                                        // check for the smallest partial statelist. Try this first - it might give 0 candidates 
                                                        // and eliminate the need to calculate the other part
                                                        if (MIN(partial_statelist[p].len[ODD_STATE], partial_statelist[r].len[ODD_STATE]) 
Impressum, Datenschutz