changeset 1559:2dbc816d48f4

Fail when a peer with empty Origin-Realm tries to connect. Empty Origin-Realms cause problems in the routing code later. Reduce warnings when reporting an empty Failed-AVP; both avp_source and avp_rawdata are NULL in this case.
author Thomas Klausner <wiz@gatalith.at>
date Tue, 27 Oct 2020 10:50:04 +0100
parents 5e29c00d6576
children 9084c6f94a0a
files libfdcore/p_ce.c libfdproto/messages.c
diffstat 2 files changed, 10 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libfdcore/p_ce.c	Tue Oct 06 21:36:41 2020 +0800
+++ b/libfdcore/p_ce.c	Tue Oct 27 10:50:04 2020 +0100
@@ -336,6 +336,14 @@
 					return EINVAL;
 				}
 				
+				/* Origin-Realm is empty */
+				if (hdr->avp_value->os.len == 0) {
+					error->pei_errcode = "DIAMETER_INVALID_AVP_VALUE";
+					error->pei_message = "Your Origin-Realm is empty.";
+					error->pei_avp = avp;
+					return EINVAL;
+				}
+
 				/* Save the value */
 				CHECK_MALLOC(  peer->p_hdr.info.runtime.pir_realm = os0dup( hdr->avp_value->os.data, hdr->avp_value->os.len )  );
 				peer->p_hdr.info.runtime.pir_realmlen = hdr->avp_value->os.len;
--- a/libfdproto/messages.c	Tue Oct 06 21:36:41 2020 +0800
+++ b/libfdproto/messages.c	Tue Oct 27 10:50:04 2020 +0100
@@ -1776,13 +1776,13 @@
 	
 	if (avp->avp_model == NULL) {
 		/* In the case where we don't know the type of AVP, just copy the raw data or source */
-		CHECK_PARAMS( avp->avp_source || avp->avp_rawdata );
+		/* there might be no data if the AVP is empty */
 		
 		if ( avp->avp_rawdata != NULL ) {
 			/* the content was stored in rawdata */
 			memcpy(&buffer[*offset], avp->avp_rawdata, avp->avp_rawlen);
 			*offset += PAD4(avp->avp_rawlen);
-		} else {
+		} else if ( avp->avp_source != NULL ) {
 			/* the message was not parsed completely */
 			size_t datalen = avp->avp_public.avp_len - GETAVPHDRSZ(avp->avp_public.avp_flags);
 			memcpy(&buffer[*offset], avp->avp_source, datalen);
"Welcome to our mercurial repository"