Merge branch 'master' into tlv-mic
[moonshot.git] / mech_eap / import_sec_context.c
index 7f81b40..978970a 100644 (file)
@@ -58,7 +58,15 @@ importPartialRadiusContext(OM_uint32 *minor,
     unsigned char *p = *pBuf;
     size_t remain = *pRemain;
     gss_buffer_desc buf;
-    size_t serverLen;
+    size_t ctxLength, serverLen;
+
+    /* Length of partial RADIUS context */
+    CHECK_REMAIN(4);
+    ctxLength = load_uint32_be(p);
+    UPDATE_REMAIN(4);
+
+    CHECK_REMAIN(ctxLength);
+    remain = ctxLength; /* check against partial context length */
 
     /* Selected RADIUS server */
     CHECK_REMAIN(4);
@@ -96,8 +104,12 @@ importPartialRadiusContext(OM_uint32 *minor,
         UPDATE_REMAIN(buf.length);
     }
 
+#ifdef GSSEAP_DEBUG
+    assert(remain == 0);
+#endif
+
     *pBuf = p;
-    *pRemain = remain;
+    *pRemain -= 4 + ctxLength;
 
     return GSS_S_COMPLETE;
 }
@@ -261,7 +273,7 @@ importConversation(OM_uint32 *minor,
     return GSS_S_COMPLETE;
 }
 
-static OM_uint32
+OM_uint32
 gssEapImportContext(OM_uint32 *minor,
                     gss_buffer_t token,
                     gss_ctx_id_t ctx)