changeset 752:9e9840ccf059

Attempt to handle more gracefully (invalid) AVPs that contain an empty octetstring
author Sebastien Decugis <sdecugis@nict.go.jp>
date Sat, 24 Sep 2011 09:45:14 +0200
parents c7d9c5477d2f
children 71833fa5e35f
files libfdproto/messages.c libfdproto/ostr.c
diffstat 2 files changed, 5 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/libfdproto/messages.c	Thu Sep 22 21:10:00 2011 +0200
+++ b/libfdproto/messages.c	Sat Sep 24 09:45:14 2011 +0200
@@ -1770,12 +1770,8 @@
 					return EBADMSG;
 				} );
 			avp->avp_storage.os.len = avp->avp_public.avp_len - GETAVPHDRSZ( avp->avp_public.avp_flags );
-			if (avp->avp_storage.os.len) {
-				CHECK_MALLOC(  avp->avp_storage.os.data = os0dup(avp->avp_source, avp->avp_storage.os.len)  );
-				avp->avp_mustfreeos = 1;
-			} else {
-				avp->avp_storage.os.data = NULL;
-			}
+			CHECK_MALLOC(  avp->avp_storage.os.data = os0dup(avp->avp_source, avp->avp_storage.os.len)  );
+			avp->avp_mustfreeos = 1;
 			break;
 		
 		case AVP_TYPE_INTEGER32:
--- a/libfdproto/ostr.c	Thu Sep 22 21:10:00 2011 +0200
+++ b/libfdproto/ostr.c	Sat Sep 24 09:45:14 2011 +0200
@@ -44,7 +44,8 @@
 os0_t os0dup_int(os0_t s, size_t l) {
 	os0_t r;
 	CHECK_MALLOC_DO( r = malloc(l+1), return NULL );
-	memcpy(r, s, l); /* this might be faster than a strcpy or strdup because it can work with 32 or 64b blocks */
+	if (l)
+		memcpy(r, s, l); /* this might be faster than a strcpy or strdup because it can work with 32 or 64b blocks */
 	r[l] = '\0';
 	return r;
 }
@@ -57,7 +58,7 @@
 		return -1;
 	if (os1sz > os2sz)
 		return 1;
-	return memcmp(os1, os2, os1sz);
+	return os1sz ? memcmp(os1, os2, os1sz) : 0;
 }
 
 /* a local version of tolower() that does not depend on LC_CTYPE locale */
"Welcome to our mercurial repository"