EAP-pwd server: Fix Total-Length parsing for fragment reassembly
authorJouni Malinen <j@w1.fi>
Sat, 2 May 2015 16:26:06 +0000 (19:26 +0300)
committerJouni Malinen <j@w1.fi>
Sun, 3 May 2015 15:26:50 +0000 (18:26 +0300)
The remaining number of bytes in the message could be smaller than the
Total-Length field size, so the length needs to be explicitly checked
prior to reading the field and decrementing the len variable. This could
have resulted in the remaining length becoming negative and interpreted
as a huge positive integer.

In addition, check that there is no already started fragment in progress
before allocating a new buffer for reassembling fragments. This avoid a
potential memory leak when processing invalid message.

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

index 3189105..2bfc3c2 100644 (file)
@@ -942,11 +942,21 @@ static void eap_pwd_process(struct eap_sm *sm, void *priv,
         * the first fragment has a total length
         */
        if (EAP_PWD_GET_LENGTH_BIT(lm_exch)) {
+               if (len < 2) {
+                       wpa_printf(MSG_DEBUG,
+                                  "EAP-pwd: Frame too short to contain Total-Length field");
+                       return;
+               }
                tot_len = WPA_GET_BE16(pos);
                wpa_printf(MSG_DEBUG, "EAP-pwd: Incoming fragments, total "
                           "length = %d", tot_len);
                if (tot_len > 15000)
                        return;
+               if (data->inbuf) {
+                       wpa_printf(MSG_DEBUG,
+                                  "EAP-pwd: Unexpected new fragment start when previous fragment is still in use");
+                       return;
+               }
                data->inbuf = wpabuf_alloc(tot_len);
                if (data->inbuf == NULL) {
                        wpa_printf(MSG_INFO, "EAP-pwd: Out of memory to "