From 424ceb58a3dad844e7dd15e8cb40cf1453997c15 Mon Sep 17 00:00:00 2001 From: Andrew Zaborowski Date: Fri, 28 Oct 2016 05:59:56 +0200 Subject: [PATCH] eapol: Drop len parameter to eapol_sm_set_rsn/wpa The len parameter was only used so it could be validated against ie[1], but since it was not checked to be > 2, it must have been validated already, the check was redundant. In any case all users directly passed ie[1] as len anyway. This makes it consistent with the ie parsers and builders which didn't require a length. --- src/device.c | 8 ++++---- src/eapol.c | 32 ++++++++++++-------------------- src/eapol.h | 12 ++++-------- 3 files changed, 20 insertions(+), 32 deletions(-) diff --git a/src/device.c b/src/device.c index be4b0627..4d013fca 100644 --- a/src/device.c +++ b/src/device.c @@ -677,12 +677,12 @@ void device_connect_network(struct device *device, struct network *network, /* RSN takes priority */ if (bss->rsne) { ie_build_rsne(&info, rsne_buf); - eapol_sm_set_ap_rsn(sm, bss->rsne, bss->rsne[1] + 2); - eapol_sm_set_own_rsn(sm, rsne_buf, rsne_buf[1] + 2); + eapol_sm_set_ap_rsn(sm, bss->rsne); + eapol_sm_set_own_rsn(sm, rsne_buf); } else { ie_build_wpa(&info, rsne_buf); - eapol_sm_set_ap_wpa(sm, bss->wpa, bss->wpa[1] + 2); - eapol_sm_set_own_wpa(sm, rsne_buf, rsne_buf[1] + 2); + eapol_sm_set_ap_wpa(sm, bss->wpa); + eapol_sm_set_own_wpa(sm, rsne_buf); } if (security == SECURITY_PSK) diff --git a/src/eapol.c b/src/eapol.c index ab38e75c..b2f2a01c 100644 --- a/src/eapol.c +++ b/src/eapol.c @@ -801,30 +801,24 @@ void eapol_sm_set_pmk(struct eapol_sm *sm, const uint8_t *pmk) } static void eapol_sm_set_ap_ie(struct eapol_sm *sm, const uint8_t *ie, - size_t len, bool is_wpa) + bool is_wpa) { - if (ie[1] + 2u != len) - return; - l_free(sm->ap_ie); - sm->ap_ie = l_memdup(ie, len); + sm->ap_ie = l_memdup(ie, ie[1] + 2u); sm->wpa_ie = is_wpa; } static void eapol_sm_set_own_ie(struct eapol_sm *sm, const uint8_t *ie, - size_t len, bool is_wpa) + bool is_wpa) { - if (ie[1] + 2u != len) - return; - l_free(sm->own_ie); - sm->own_ie = l_memdup(ie, len); + sm->own_ie = l_memdup(ie, ie[1] + 2u); sm->wpa_ie = is_wpa; } -void eapol_sm_set_ap_rsn(struct eapol_sm *sm, const uint8_t *rsn_ie, size_t len) +void eapol_sm_set_ap_rsn(struct eapol_sm *sm, const uint8_t *rsn_ie) { - eapol_sm_set_ap_ie(sm, rsn_ie, len, false); + eapol_sm_set_ap_ie(sm, rsn_ie, false); } static bool eapol_sm_setup_own_ciphers(struct eapol_sm *sm, @@ -845,12 +839,11 @@ static bool eapol_sm_setup_own_ciphers(struct eapol_sm *sm, return true; } -bool eapol_sm_set_own_rsn(struct eapol_sm *sm, const uint8_t *rsn_ie, - size_t len) +bool eapol_sm_set_own_rsn(struct eapol_sm *sm, const uint8_t *rsn_ie) { struct ie_rsn_info info; - eapol_sm_set_own_ie(sm, rsn_ie, len, false); + eapol_sm_set_own_ie(sm, rsn_ie, false); if (ie_parse_rsne_from_data(rsn_ie, rsn_ie[1] + 2, &info) < 0) return false; @@ -858,17 +851,16 @@ bool eapol_sm_set_own_rsn(struct eapol_sm *sm, const uint8_t *rsn_ie, return eapol_sm_setup_own_ciphers(sm, &info); } -void eapol_sm_set_ap_wpa(struct eapol_sm *sm, const uint8_t *wpa_ie, size_t len) +void eapol_sm_set_ap_wpa(struct eapol_sm *sm, const uint8_t *wpa_ie) { - eapol_sm_set_ap_ie(sm, wpa_ie, len, true); + eapol_sm_set_ap_ie(sm, wpa_ie, true); } -bool eapol_sm_set_own_wpa(struct eapol_sm *sm, const uint8_t *wpa_ie, - size_t len) +bool eapol_sm_set_own_wpa(struct eapol_sm *sm, const uint8_t *wpa_ie) { struct ie_rsn_info info; - eapol_sm_set_own_ie(sm, wpa_ie, len, true); + eapol_sm_set_own_ie(sm, wpa_ie, true); if (ie_parse_wpa_from_data(wpa_ie, wpa_ie[1] + 2, &info) < 0) return false; diff --git a/src/eapol.h b/src/eapol.h index 6b98e5d1..4d7163e0 100644 --- a/src/eapol.h +++ b/src/eapol.h @@ -197,14 +197,10 @@ void eapol_sm_set_pmk(struct eapol_sm *sm, const uint8_t *pmk); void eapol_sm_set_8021x_config(struct eapol_sm *sm, struct l_settings *settings); void eapol_sm_set_use_eapol_start(struct eapol_sm *sm, bool enabled); -void eapol_sm_set_ap_rsn(struct eapol_sm *sm, const uint8_t *rsn_ie, - size_t len); -bool eapol_sm_set_own_rsn(struct eapol_sm *sm, const uint8_t *rsn_ie, - size_t len); -void eapol_sm_set_ap_wpa(struct eapol_sm *sm, const uint8_t *wpa_ie, - size_t len); -bool eapol_sm_set_own_wpa(struct eapol_sm *sm, const uint8_t *wpa_ie, - size_t len); +void eapol_sm_set_ap_rsn(struct eapol_sm *sm, const uint8_t *rsn_ie); +bool eapol_sm_set_own_rsn(struct eapol_sm *sm, const uint8_t *rsn_ie); +void eapol_sm_set_ap_wpa(struct eapol_sm *sm, const uint8_t *wpa_ie); +bool eapol_sm_set_own_wpa(struct eapol_sm *sm, const uint8_t *wpa_ie); void eapol_sm_set_user_data(struct eapol_sm *sm, void *user_data); void eapol_sm_set_event_func(struct eapol_sm *sm, eapol_sm_event_func_t func);