turn VERIFY_VP into a function, the macro was getting very long
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 2 May 2014 16:17:21 +0000 (17:17 +0100)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 2 May 2014 16:41:13 +0000 (17:41 +0100)
src/include/libradius.h
src/lib/debug.c

index c077d86..2a048a0 100644 (file)
@@ -102,31 +102,7 @@ extern "C" {
  *  Add if (_x->da) (void) talloc_get_type_abort(_x->da, DICT_ATTR);
  *  to the macro below when dictionaries are talloced.
  */
-#  define VERIFY_VP(_x) \
-do {\
-       (void) talloc_get_type_abort(_x, VALUE_PAIR);\
-       if ((_x)->data.ptr) switch ((_x)->da->type) {\
-       case PW_TYPE_OCTETS:\
-       case PW_TYPE_TLV:\
-               if (!talloc_get_type((_x)->data.ptr, uint8_t)) {\
-                       fr_perror("Type check failed for attribute \"%s\"", (_x)->da->name);\
-                       (void) talloc_get_type_abort((_x)->data.ptr, uint8_t);\
-               }\
-               fr_assert((_x)->length == talloc_array_length((_x)->vp_octets));\
-               break;\
-       case PW_TYPE_STRING:\
-               if (!talloc_get_type((_x)->data.ptr, char)) {\
-                       fr_perror("Type check failed for attribute \"%s\"", (_x)->da->name);\
-                       (void) talloc_get_type_abort((_x)->data.ptr, char);\
-               }\
-               fr_assert((_x)->length == (talloc_array_length((_x)->vp_strvalue) - 1));\
-               fr_assert((_x)->vp_strvalue[(_x)->length] == '\0');\
-               break;\
-       default:\
-               break;\
-       }\
-} while (0)\
-
+#  define VERIFY_VP(_x) fr_verify_vp(_x)
 #  define VERIFY_LIST(_x) fr_verify_list(NULL, _x)
 #  define VERIFY_PACKET(_x) (void) talloc_get_type_abort(_x, RADIUS_PACKET)
 #else
@@ -765,6 +741,7 @@ void                fr_fault_set_log_fn(fr_fault_log_t func);
 void           fr_fault_set_log_fd(int fd);
 
 #ifdef WITH_VERIFY_PTR
+void           fr_verify_vp(VALUE_PAIR const *vp);
 void           fr_verify_list(TALLOC_CTX *expected, VALUE_PAIR *vps);
 #endif
 
index f12c06c..dc568bf 100644 (file)
@@ -646,6 +646,59 @@ void fr_fault_set_log_fd(int fd)
 
 
 #ifdef WITH_VERIFY_PTR
+
+/*
+ *     Verify a VALUE_PAIR
+ */
+inline void fr_verify_vp(VALUE_PAIR const *vp)
+{
+       (void) talloc_get_type_abort(vp, VALUE_PAIR);
+
+       if (vp->data.ptr) switch (vp->da->type) {
+       case PW_TYPE_OCTETS:
+       case PW_TYPE_TLV:
+       {
+               size_t len;
+
+               if (!talloc_get_type(vp->data.ptr, uint8_t)) {
+                       fr_perror("Type check failed for attribute \"%s\"", vp->da->name);
+                       (void) talloc_get_type_abort(vp->data.ptr, uint8_t);
+               }
+
+               len = talloc_array_length(vp->vp_octets);
+               if (vp->length != len) {
+                       fr_perror("VALUE_PAIR length %zu does not equal uint8_t buffer length %zu", vp->length, len);
+                       fr_assert(0);
+               }
+       }
+               break;
+
+       case PW_TYPE_STRING:
+       {
+               size_t len;
+
+               if (!talloc_get_type(vp->data.ptr, char)) {
+                       fr_perror("Type check failed for attribute \"%s\"", vp->da->name);
+                       (void) talloc_get_type_abort(vp->data.ptr, char);
+               }
+
+               len = (talloc_array_length(vp->vp_strvalue) - 1);
+               if (vp->length != len) {
+                       fr_perror("VALUE_PAIR length %zu does not equal char buffer length %zu", vp->length, len);
+                       fr_assert(0);
+               }
+               if (vp->vp_strvalue[vp->length] != '\0') {
+                       fr_perror("VALUE_PAIR buffer not \\0 terminated");
+                       fr_assert(0);
+               }
+       }
+               break;
+
+       default:
+               break;
+       }
+}
+
 /*
  *     Verify a pair list
  */