Free memory if out of memory
[freeradius.git] / src / modules / rlm_eap / types / rlm_eap_md5 / eap_md5.c
index b92fa87..f87c8de 100644 (file)
  *
  *   You should have received a copy of the GNU General Public License
  *   along with this program; if not, write to the Free Software
- *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  *
- * Copyright 2000,2001  The FreeRADIUS server project
+ * Copyright 2000,2001,2006  The FreeRADIUS server project
  * Copyright 2001  hereUare Communications, Inc. <raghud@hereuare.com>
  */
 
 /*
  *
  *  MD5 Packet Format in EAP Type-Data
- *  --- ------ ------ -- --- --------- 
+ *  --- ------ ------ -- --- ---------
  *  0                   1                   2                   3
  *  0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@@ -35,6 +35,9 @@
  *
  */
 
+#include <freeradius-devel/ident.h>
+RCSID("$Id$")
+
 #include <stdio.h>
 #include <stdlib.h>
 #include "eap.h"
@@ -75,9 +78,9 @@ void eapmd5_free(MD5_PACKET **md5_packet_ptr)
        *md5_packet_ptr = NULL;
 }
 
-/* 
+/*
  *     We expect only RESPONSE for which SUCCESS or FAILURE is sent back
- */ 
+ */
 MD5_PACKET *eapmd5_extract(EAP_DS *eap_ds)
 {
        md5_packet_t    *data;
@@ -89,8 +92,8 @@ MD5_PACKET *eapmd5_extract(EAP_DS *eap_ds)
         *      one byte of type data (EAP-MD5) following the 4-byte
         *      EAP-Packet header.
         */
-       if (!eap_ds                                      || 
-           !eap_ds->response                            || 
+       if (!eap_ds                                      ||
+           !eap_ds->response                            ||
            (eap_ds->response->code != PW_MD5_RESPONSE)  ||
            eap_ds->response->type.type != PW_EAP_MD5    ||
            !eap_ds->response->type.data                 ||
@@ -157,10 +160,10 @@ MD5_PACKET *eapmd5_extract(EAP_DS *eap_ds)
 }
 
 
-/* 
+/*
  * verify = MD5(id+password+challenge_sent)
  */
-int eapmd5_verify(MD5_PACKET *packet, VALUE_PAIR* password, 
+int eapmd5_verify(MD5_PACKET *packet, VALUE_PAIR* password,
                  uint8_t *challenge)
 {
        char    *ptr;
@@ -184,7 +187,7 @@ int eapmd5_verify(MD5_PACKET *packet, VALUE_PAIR* password,
         */
        *ptr++ = packet->id;
        len++;
-       memcpy(ptr, password->strvalue, password->length);
+       memcpy(ptr, password->vp_strvalue, password->length);
        ptr += password->length;
        len += password->length;
 
@@ -194,7 +197,7 @@ int eapmd5_verify(MD5_PACKET *packet, VALUE_PAIR* password,
        memcpy(ptr, challenge, MD5_CHALLENGE_LEN);
        len += MD5_CHALLENGE_LEN;
 
-       librad_md5_calc((u_char *)output, (u_char *)string, len);
+       fr_md5_calc((u_char *)output, (u_char *)string, len);
 
        /*
         *      The length of the response is always 16 for MD5.
@@ -205,7 +208,7 @@ int eapmd5_verify(MD5_PACKET *packet, VALUE_PAIR* password,
        return 1;
 }
 
-/* 
+/*
  *     Compose the portions of the reply packet specific to the
  *     EAP-MD5 protocol, in the EAP reply typedata
  */
@@ -222,10 +225,10 @@ int eapmd5_compose(EAP_DS *eap_ds, MD5_PACKET *reply)
                eap_ds->request->type.type = PW_EAP_MD5;
 
                rad_assert(reply->length > 0);
-               rad_assert(reply->value_size < 256);
 
                eap_ds->request->type.data = malloc(reply->length);
                if (eap_ds->request->type.data == NULL) {
+                       eapmd5_free(&reply);
                        radlog(L_ERR, "rlm_eap_md5: out of memory");
                        return 0;
                }