diff options
author | Marc <foxtrot@malloc.me> | 2022-01-12 22:19:01 +0000 |
---|---|---|
committer | Marc <foxtrot@malloc.me> | 2022-01-12 22:19:01 +0000 |
commit | 2057ed8028b4a5c951ed5b6005c5088890c1e689 (patch) | |
tree | 5e5f8090c317af898161966a442b2473d2086a67 /src | |
parent | fe955af4811c73768f77ef9471550648df0b8ec8 (diff) | |
download | libwifi-2057ed8028b4a5c951ed5b6005c5088890c1e689.tar.gz libwifi-2057ed8028b4a5c951ed5b6005c5088890c1e689.tar.bz2 libwifi-2057ed8028b4a5c951ed5b6005c5088890c1e689.zip |
parse: Check frame minimum length when parsing Radiotap header
Diffstat (limited to 'src')
-rw-r--r-- | src/libwifi/core/frame/frame.c | 2 | ||||
-rw-r--r-- | src/libwifi/parse/misc/radiotap.c | 9 | ||||
-rw-r--r-- | src/libwifi/parse/misc/radiotap.h | 7 |
3 files changed, 14 insertions, 4 deletions
diff --git a/src/libwifi/core/frame/frame.c b/src/libwifi/core/frame/frame.c index b4f50ad..78fe069 100644 --- a/src/libwifi/core/frame/frame.c +++ b/src/libwifi/core/frame/frame.c | |||
@@ -42,7 +42,7 @@ int libwifi_get_wifi_frame(struct libwifi_frame *fi, const unsigned char *frame, | |||
42 | 42 | ||
43 | if (radiotap) { | 43 | if (radiotap) { |
44 | struct libwifi_radiotap_info rtap_info = {0}; | 44 | struct libwifi_radiotap_info rtap_info = {0}; |
45 | libwifi_parse_radiotap_info(&rtap_info, frame_data); | 45 | libwifi_parse_radiotap_info(&rtap_info, frame_data, frame_len); |
46 | 46 | ||
47 | // Skip forward by the length of the radiotap header | 47 | // Skip forward by the length of the radiotap header |
48 | frame_data_len -= rtap_info.length; | 48 | frame_data_len -= rtap_info.length; |
diff --git a/src/libwifi/parse/misc/radiotap.c b/src/libwifi/parse/misc/radiotap.c index 176167e..80ddced 100644 --- a/src/libwifi/parse/misc/radiotap.c +++ b/src/libwifi/parse/misc/radiotap.c | |||
@@ -16,6 +16,7 @@ | |||
16 | #include "radiotap.h" | 16 | #include "radiotap.h" |
17 | #include "../../core/radiotap/radiotap_iter.h" | 17 | #include "../../core/radiotap/radiotap_iter.h" |
18 | 18 | ||
19 | #include <errno.h> | ||
19 | #include <endian.h> | 20 | #include <endian.h> |
20 | #include <stdint.h> | 21 | #include <stdint.h> |
21 | 22 | ||
@@ -23,9 +24,13 @@ | |||
23 | * The libwifi radiotap parser uses the usual ieee80211_radiotap_iterator to parse incoming | 24 | * The libwifi radiotap parser uses the usual ieee80211_radiotap_iterator to parse incoming |
24 | * radiotap headers into a consumable libwifi_radiotap_info struct. | 25 | * radiotap headers into a consumable libwifi_radiotap_info struct. |
25 | */ | 26 | */ |
26 | void libwifi_parse_radiotap_info(struct libwifi_radiotap_info *info, const unsigned char *frame) { | 27 | int libwifi_parse_radiotap_info(struct libwifi_radiotap_info *info, const unsigned char *frame, size_t frame_len) { |
27 | memset(info, 0, sizeof(struct libwifi_radiotap_info)); | 28 | memset(info, 0, sizeof(struct libwifi_radiotap_info)); |
28 | 29 | ||
30 | if (frame_len < sizeof(struct ieee80211_radiotap_header)) { | ||
31 | return -EINVAL; | ||
32 | } | ||
33 | |||
29 | struct ieee80211_radiotap_header *rh = (struct ieee80211_radiotap_header *) frame; | 34 | struct ieee80211_radiotap_header *rh = (struct ieee80211_radiotap_header *) frame; |
30 | struct ieee80211_radiotap_iterator it = {0}; | 35 | struct ieee80211_radiotap_iterator it = {0}; |
31 | int ret = ieee80211_radiotap_iterator_init(&it, (void *) frame, rh->it_len, NULL); | 36 | int ret = ieee80211_radiotap_iterator_init(&it, (void *) frame, rh->it_len, NULL); |
@@ -99,6 +104,8 @@ void libwifi_parse_radiotap_info(struct libwifi_radiotap_info *info, const unsig | |||
99 | 104 | ||
100 | ret = ieee80211_radiotap_iterator_next(&it); | 105 | ret = ieee80211_radiotap_iterator_next(&it); |
101 | } | 106 | } |
107 | |||
108 | return 0; | ||
102 | } | 109 | } |
103 | 110 | ||
104 | /** | 111 | /** |
diff --git a/src/libwifi/parse/misc/radiotap.h b/src/libwifi/parse/misc/radiotap.h index 8f74e6a..d57a760 100644 --- a/src/libwifi/parse/misc/radiotap.h +++ b/src/libwifi/parse/misc/radiotap.h | |||
@@ -17,6 +17,7 @@ | |||
17 | #define LIBWIFI_PARSE_RADIOTAP_H | 17 | #define LIBWIFI_PARSE_RADIOTAP_H |
18 | 18 | ||
19 | #include "../../core/misc/radiotap.h" | 19 | #include "../../core/misc/radiotap.h" |
20 | #include <stddef.h> | ||
20 | #include <stdint.h> | 21 | #include <stdint.h> |
21 | 22 | ||
22 | /** | 23 | /** |
@@ -25,8 +26,10 @@ | |||
25 | * | 26 | * |
26 | * @param info A libwifi_radiotap_info | 27 | * @param info A libwifi_radiotap_info |
27 | * @param frame A raw 802.11 frame | 28 | * @param frame A raw 802.11 frame |
28 | */ | 29 | * @param frame_len Length of the given 802.11 frame |
29 | void libwifi_parse_radiotap_info(struct libwifi_radiotap_info *info, const unsigned char *frame); | 30 | * @returns Negative errno on error, 0 on success |
31 | */ | ||
32 | int libwifi_parse_radiotap_info(struct libwifi_radiotap_info *info, const unsigned char *frame, size_t frame_len); | ||
30 | 33 | ||
31 | /** | 34 | /** |
32 | * Retrieve the signal strength from a raw frame via radiotap header. | 35 | * Retrieve the signal strength from a raw frame via radiotap header. |