Index: extensions/app_diameap/diameap_mysql.c
===================================================================
--- extensions/app_diameap/diameap_mysql.c	(revision 444)
+++ extensions/app_diameap/diameap_mysql.c	(revision 577)
@@ -83,9 +83,9 @@
 
 		user->id = atoi(row[0]);
-		CHECK_MALLOC(user->userid=malloc(strlen(row[1])));
-		memcpy(user->userid,row[1],strlen(row[1]));
+		CHECK_MALLOC(user->userid=malloc(strlen(row[1])+1));
+		memcpy(user->userid,row[1],strlen(row[1])+1);
 		user->useridLength = strlen(row[1]);
-		CHECK_MALLOC(user->password=malloc(strlen(row[2])));
-		memcpy(user->password, row[2],strlen(row[2]));
+		CHECK_MALLOC(user->password=malloc(strlen(row[2])+1));
+		memcpy(user->password, row[2],strlen(row[2])+1);
 		user->passwordLength = strlen(row[2]);
 		user->proposed_eap_method = atoi(row[3]);
Index: extensions/app_diameap/diameap_server.c
===================================================================
--- extensions/app_diameap/diameap_server.c	(revision 565)
+++ extensions/app_diameap/diameap_server.c	(revision 577)
@@ -161,6 +161,6 @@
 			diameap_sm->eap_sm.user.useridLength
 					= diameap_sess_data->user.useridLength;
-			CHECK_MALLOC(diameap_sm->eap_sm.user.userid= malloc(diameap_sm->eap_sm.user.useridLength));
-			U8COPY(diameap_sm->eap_sm.user.userid,0,diameap_sm->eap_sm.user.useridLength,diameap_sess_data->user.userid);
+			CHECK_MALLOC(diameap_sm->eap_sm.user.userid= malloc(diameap_sm->eap_sm.user.useridLength+1));
+			U8COPY(diameap_sm->eap_sm.user.userid,0,diameap_sm->eap_sm.user.useridLength+1,diameap_sess_data->user.userid);
 			free(diameap_sess_data->user.userid);
 			diameap_sess_data->user.userid = NULL;
@@ -179,6 +179,6 @@
 			diameap_sm->eap_sm.user.passwordLength
 					= diameap_sess_data->user.passwordLength;
-			CHECK_MALLOC(diameap_sm->eap_sm.user.password = malloc(diameap_sm->eap_sm.user.passwordLength));
-			U8COPY(diameap_sm->eap_sm.user.password,0,diameap_sm->eap_sm.user.passwordLength, diameap_sess_data->user.password);
+			CHECK_MALLOC(diameap_sm->eap_sm.user.password = malloc(diameap_sm->eap_sm.user.passwordLength+1));
+			U8COPY(diameap_sm->eap_sm.user.password,0,diameap_sm->eap_sm.user.passwordLength+1, diameap_sess_data->user.password);
 			free(diameap_sess_data->user.password);
 			diameap_sess_data->user.password = NULL;
@@ -1033,6 +1033,6 @@
 		diameap_sess_data->user.useridLength
 				= diameap_sm->eap_sm.user.useridLength;
-		CHECK_MALLOC(diameap_sess_data->user.userid= malloc(diameap_sess_data->user.useridLength));
-		U8COPY(diameap_sess_data->user.userid,0,diameap_sess_data->user.useridLength,diameap_sm->eap_sm.user.userid);
+		CHECK_MALLOC(diameap_sess_data->user.userid= malloc(diameap_sess_data->user.useridLength+1));
+		U8COPY(diameap_sess_data->user.userid,0,diameap_sess_data->user.useridLength+1,diameap_sm->eap_sm.user.userid);
 		free(diameap_sm->eap_sm.user.userid);
 		diameap_sm->eap_sm.user.userid = NULL;
@@ -1050,6 +1050,6 @@
 		diameap_sess_data->user.passwordLength
 				= diameap_sm->eap_sm.user.passwordLength;
-		CHECK_MALLOC(diameap_sess_data->user.password = malloc(diameap_sess_data->user.passwordLength));
-		U8COPY(diameap_sess_data->user.password,0,diameap_sess_data->user.passwordLength,diameap_sm->eap_sm.user.password);
+		CHECK_MALLOC(diameap_sess_data->user.password = malloc(diameap_sess_data->user.passwordLength+1));
+		U8COPY(diameap_sess_data->user.password,0,diameap_sess_data->user.passwordLength+1,diameap_sm->eap_sm.user.password);
 		free(diameap_sm->eap_sm.user.password);
 		diameap_sm->eap_sm.user.password = NULL;
Index: extensions/app_diameap/plugins/eap_identity/eap_identity.c
===================================================================
--- extensions/app_diameap/plugins/eap_identity/eap_identity.c	(revision 565)
+++ extensions/app_diameap/plugins/eap_identity/eap_identity.c	(revision 577)
@@ -141,5 +141,5 @@
 		ret=diameap_get_eap_user(&(smd->user),"Default User");
 		CHECK_MALLOC_DO(smd->user.userid=realloc(smd->user.userid,strlen(user)+1),{ret = 1; goto next;});
-		memcpy(smd->user.userid,user,strlen(user));
+		memcpy(smd->user.userid,user,strlen(user)+1);
 		smd->user.useridLength = strlen(user);
 	} else {
Index: extensions/app_diameap/plugins/eap_tls/eap_tls.c
===================================================================
--- extensions/app_diameap/plugins/eap_tls/eap_tls.c	(revision 565)
+++ extensions/app_diameap/plugins/eap_tls/eap_tls.c	(revision 577)
@@ -220,5 +220,5 @@
 						goto failure;});
 
-					if(strcmp((char *)smd->user.userid,buff)!=0){
+					if(strncmp((char *)smd->user.userid,buff,smd->user.useridLength)!=0){
 						goto failure;
 					}
