# HG changeset patch # User Sebastien Decugis # Date 1316850314 -7200 # Node ID 9e9840ccf05922bf68a9470f399c76a8526c4b26 # Parent c7d9c5477d2f3b7de65466d4bd4a133af21f3028 Attempt to handle more gracefully (invalid) AVPs that contain an empty octetstring diff -r c7d9c5477d2f -r 9e9840ccf059 libfdproto/messages.c --- 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: diff -r c7d9c5477d2f -r 9e9840ccf059 libfdproto/ostr.c --- 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 */