fix hostapd/madwifi crash (#247)
[openwrt/svn-archive/archive.git] / openwrt / package / hostapd / patches / 100-wpa_fix.patch
1 --- hostapd-0.4.7/driver_madwifi.c 2006-01-30 10:00:44.199096000 -0800
2 +++ hostapd-0.4.7-new/driver_madwifi.c 2006-01-30 10:05:55.925511000 -0800
3 @@ -692,6 +692,7 @@
4 struct hostapd_data *hapd = drv->hapd;
5 struct ieee80211req_wpaie ie;
6 int ielen, res;
7 + int rsn = 0;
8
9 /*
10 * Fetch negotiated WPA/RSN parameters from the system.
11 @@ -702,26 +703,37 @@
12 printf("Failed to get WPA/RSN information element.\n");
13 return -1; /* XXX not right */
14 }
15 - ielen = ie.wpa_ie[1];
16 - if (ielen == 0) {
17 + if ((ie.wpa_ie[1] == 0) && (ie.rsn_ie[1] == 0)){
18 printf("No WPA/RSN information element for station!?\n");
19 return -1; /* XXX not right */
20 }
21 + ielen = ie.rsn_ie[1];
22 ielen += 2;
23 - res = wpa_validate_wpa_ie(hapd, sta, ie.wpa_ie, ielen,
24 - ie.wpa_ie[0] == WLAN_EID_RSN ?
25 - HOSTAPD_WPA_VERSION_WPA2 : HOSTAPD_WPA_VERSION_WPA);
26 - if (res != WPA_IE_OK) {
27 - printf("WPA/RSN information element rejected? (res %u)\n", res);
28 - return -1;
29 - }
30 + res = wpa_validate_wpa_ie(hapd, sta, ie.rsn_ie, ielen,
31 + HOSTAPD_WPA_VERSION_WPA2);
32 + if (res != WPA_IE_OK){
33 + // now look for WPA IE
34 + ielen = ie.wpa_ie[1];
35 + ielen += 2;
36 + res = wpa_validate_wpa_ie(hapd, sta, ie.wpa_ie, ielen,
37 + HOSTAPD_WPA_VERSION_WPA);
38 + if (res != WPA_IE_OK) {
39 + printf("WPA/RSN information element rejected? (res %u)\n", res);
40 + return -1;
41 + }
42 + } else {
43 + rsn = 1;
44 + }
45 free(sta->wpa_ie);
46 sta->wpa_ie = malloc(ielen);
47 if (sta->wpa_ie == NULL) {
48 printf("No memory to save WPA/RSN information element!\n");
49 return -1;
50 }
51 - memcpy(sta->wpa_ie, ie.wpa_ie, ielen);
52 + if (rsn)
53 + memcpy(sta->wpa_ie, ie.rsn_ie, ielen);
54 + else
55 + memcpy(sta->wpa_ie, ie.wpa_ie, ielen);
56 sta->wpa_ie_len = ielen;
57 return 0;
58 }