]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
SAE: Avoid undefined behavior in pointer arithmetic
authorJouni Malinen <j@w1.fi>
Sun, 18 Oct 2015 15:49:56 +0000 (18:49 +0300)
committerJouni Malinen <j@w1.fi>
Sun, 25 Oct 2015 13:34:59 +0000 (15:34 +0200)
Reorder terms in a way that no invalid pointers are generated with
pos+len operations. end-pos is always defined (with a valid pos pointer)
while pos+len could end up pointing beyond the end pointer which would
be undefined behavior.

Signed-off-by: Jouni Malinen <j@w1.fi>
src/common/sae.c

index 503fa1d7b9a96143c778a8d6f38965b1469c070d..b962ea227434c4885ea08cbaa28adb78f4b4524c 100644 (file)
@@ -923,7 +923,7 @@ static void sae_parse_commit_token(struct sae_data *sae, const u8 **pos,
                                   const u8 *end, const u8 **token,
                                   size_t *token_len)
 {
-       if (*pos + (sae->tmp->ec ? 3 : 2) * sae->tmp->prime_len < end) {
+       if ((sae->tmp->ec ? 3 : 2) * sae->tmp->prime_len < end - *pos) {
                size_t tlen = end - (*pos + (sae->tmp->ec ? 3 : 2) *
                                     sae->tmp->prime_len);
                wpa_hexdump(MSG_DEBUG, "SAE: Anti-Clogging Token", *pos, tlen);
@@ -946,7 +946,7 @@ static u16 sae_parse_commit_scalar(struct sae_data *sae, const u8 **pos,
 {
        struct crypto_bignum *peer_scalar;
 
-       if (*pos + sae->tmp->prime_len > end) {
+       if (sae->tmp->prime_len > end - *pos) {
                wpa_printf(MSG_DEBUG, "SAE: Not enough data for scalar");
                return WLAN_STATUS_UNSPECIFIED_FAILURE;
        }
@@ -994,7 +994,7 @@ static u16 sae_parse_commit_element_ecc(struct sae_data *sae, const u8 *pos,
 {
        u8 prime[SAE_MAX_ECC_PRIME_LEN];
 
-       if (pos + 2 * sae->tmp->prime_len > end) {
+       if (2 * sae->tmp->prime_len > end - pos) {
                wpa_printf(MSG_DEBUG, "SAE: Not enough data for "
                           "commit-element");
                return WLAN_STATUS_UNSPECIFIED_FAILURE;
@@ -1040,7 +1040,7 @@ static u16 sae_parse_commit_element_ffc(struct sae_data *sae, const u8 *pos,
        struct crypto_bignum *res, *one;
        const u8 one_bin[1] = { 0x01 };
 
-       if (pos + sae->tmp->prime_len > end) {
+       if (sae->tmp->prime_len > end - pos) {
                wpa_printf(MSG_DEBUG, "SAE: Not enough data for "
                           "commit-element");
                return WLAN_STATUS_UNSPECIFIED_FAILURE;
@@ -1098,7 +1098,7 @@ u16 sae_parse_commit(struct sae_data *sae, const u8 *data, size_t len,
        u16 res;
 
        /* Check Finite Cyclic Group */
-       if (pos + 2 > end)
+       if (end - pos < 2)
                return WLAN_STATUS_UNSPECIFIED_FAILURE;
        res = sae_group_allowed(sae, allowed_groups, WPA_GET_LE16(pos));
        if (res != WLAN_STATUS_SUCCESS)