Print file and line number in VERIFY_* messages
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 17 Jun 2014 12:49:54 +0000 (13:49 +0100)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 17 Jun 2014 12:49:54 +0000 (13:49 +0100)
src/include/libradius.h
src/include/radiusd.h
src/lib/debug.c
src/main/util.c

index fb79c37..b5976ac 100644 (file)
@@ -106,8 +106,8 @@ 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)                fr_verify_vp(_x)
-#  define VERIFY_LIST(_x)      fr_verify_list(NULL, _x)
+#  define VERIFY_VP(_x)                fr_verify_vp(__FILE__,  __LINE__, _x)
+#  define VERIFY_LIST(_x)      fr_verify_list(__FILE__,  __LINE__, NULL, _x)
 #  define VERIFY_PACKET(_x)    (void) talloc_get_type_abort(_x, RADIUS_PACKET)
 #else
 /*
@@ -760,8 +760,8 @@ 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);
+void           fr_verify_vp(char const *file, int line, VALUE_PAIR const *vp);
+void           fr_verify_list(char const *file, int line, TALLOC_CTX *expected, VALUE_PAIR *vps);
 #endif
 
 /* rbtree.c */
index a6bf8ef..2ba9309 100644 (file)
@@ -189,7 +189,7 @@ typedef             int (*RAD_REQUEST_FUNP)(REQUEST *);
 #define REQUEST_MAX_REGEX (8)
 
 #if defined(WITH_VERIFY_PTR)
-#  define VERIFY_REQUEST(_x) verify_request(_x)
+#  define VERIFY_REQUEST(_x) verify_request(__FILE__, __LINE__, _x)
 #else
 /*
  *  Even if were building without WITH_VERIFY_PTR
@@ -554,7 +554,7 @@ int         rad_expand_xlat(REQUEST *request, char const *cmd,
                                size_t argv_buflen, char *argv_buf);
 void           rad_regcapture(REQUEST *request, int compare, char const *value,
                               regmatch_t rxmatch[]);
-void           verify_request(REQUEST *request);                       /* only for special debug builds */
+void           verify_request(char const *file, int line, REQUEST *request);   /* only for special debug builds */
 
 /* client.c */
 RADCLIENT_LIST *clients_init(CONF_SECTION *cs);
index 928c2f8..f5702a1 100644 (file)
@@ -799,7 +799,7 @@ void fr_fault_set_log_fd(int fd)
 /*
  *     Verify a VALUE_PAIR
  */
-inline void fr_verify_vp(VALUE_PAIR const *vp)
+inline void fr_verify_vp(char const *file, int line, VALUE_PAIR const *vp)
 {
        (void) talloc_get_type_abort(vp, VALUE_PAIR);
 
@@ -810,13 +810,15 @@ inline void fr_verify_vp(VALUE_PAIR const *vp)
                size_t len;
 
                if (!talloc_get_type(vp->data.ptr, uint8_t)) {
-                       fprintf(stderr, "Type check failed for attribute \"%s\"", vp->da->name);
+                       fprintf(stderr, "CONSISTENCY CHECK FAILED %s[%u]: Attribute \"%s\" value buffer type should be "
+                               "uint8_t but is %s", file, line, vp->da->name, talloc_get_name(vp->data.ptr));
                        (void) talloc_get_type_abort(vp->data.ptr, uint8_t);
                }
 
                len = talloc_array_length(vp->vp_octets);
                if (vp->length > len) {
-                       fprintf(stderr, "VALUE_PAIR length %zu does not equal uint8_t buffer length %zu", vp->length, len);
+                       fprintf(stderr, "CONSISTENCY CHECK FAILED %s[%u]: VALUE_PAIR length %zu does not equal uint8_t "
+                               "value buffer length %zu", file, line, vp->length, len);
                        fr_assert(0);
                        fr_exit_now(1);
                }
@@ -828,19 +830,21 @@ inline void fr_verify_vp(VALUE_PAIR const *vp)
                size_t len;
 
                if (!talloc_get_type(vp->data.ptr, char)) {
-                       fprintf(stderr, "Type check failed for attribute \"%s\"", vp->da->name);
+                       fprintf(stderr, "CONSISTENCY CHECK FAILED %s[%u]: Attribute \"%s\" value buffer type should be "
+                               "char but is %s", file, line, vp->da->name, talloc_get_name(vp->data.ptr));
                        (void) talloc_get_type_abort(vp->data.ptr, char);
                }
 
                len = (talloc_array_length(vp->vp_strvalue) - 1);
                if (vp->length > len) {
-                       fprintf(stderr, "VALUE_PAIR %s length %zu is too small for char buffer length %zu",
-                                 vp->da->name, vp->length, len);
+                       fprintf(stderr, "CONSISTENCY CHECK FAILED %s[%u]: VALUE_PAIR %s length %zu is too small for "
+                               "char buffer length %zu", file, line, vp->da->name, vp->length, len);
                        fr_assert(0);
                        fr_exit_now(1);
                }
                if (vp->vp_strvalue[vp->length] != '\0') {
-                       fprintf(stderr, "VALUE_PAIR %s buffer not \\0 terminated", vp->da->name);
+                       fprintf(stderr, "CONSISTENCY CHECK FAILED %s[%u]: VALUE_PAIR %s buffer not \\0 terminated",
+                               file, line, vp->da->name);
                        fr_assert(0);
                        fr_exit_now(1);
                }
@@ -855,7 +859,7 @@ inline void fr_verify_vp(VALUE_PAIR const *vp)
 /*
  *     Verify a pair list
  */
-void fr_verify_list(TALLOC_CTX *expected, VALUE_PAIR *vps)
+void fr_verify_list(char const *file, int line, TALLOC_CTX *expected, VALUE_PAIR *vps)
 {
        vp_cursor_t cursor;
        VALUE_PAIR *vp;
@@ -868,9 +872,9 @@ void fr_verify_list(TALLOC_CTX *expected, VALUE_PAIR *vps)
 
                parent = talloc_parent(vp);
                if (expected && (parent != expected)) {
-                       fprintf(stderr, "Expected VALUE_PAIR (%s) to be parented by %p (%s), "
-                               "but parented by %p (%s)",
-                               vp->da->name,
+                       fprintf(stderr, "CONSISTENCY CHECK FAILED %s[%u]: Expected VALUE_PAIR (%s) to be parented "
+                               "by %p (%s), but parented by %p (%s)",
+                               file, line, vp->da->name,
                                expected, talloc_get_name(expected),
                                parent, parent ? talloc_get_name(parent) : "NULL");
 
index d569517..71095dd 100644 (file)
@@ -1066,7 +1066,7 @@ void rad_regcapture(REQUEST *request, int compare, char const *value, regmatch_t
 /*
  *     Verify a packet.
  */
-static void verify_packet(REQUEST *request, RADIUS_PACKET *packet)
+static void verify_packet(char const *file, int line, REQUEST *request, RADIUS_PACKET *packet)
 {
        TALLOC_CTX *parent;
 
@@ -1074,9 +1074,8 @@ static void verify_packet(REQUEST *request, RADIUS_PACKET *packet)
 
        parent = talloc_parent(packet);
        if (parent != request) {
-               ERROR("Expected RADIUS_PACKET to be parented by %p (%s), "
-                     "but parented by %p (%s)",
-                     request, talloc_get_name(request),
+               ERROR("CONSISTENCY CHECK FAILED %s[%u]: Expected RADIUS_PACKET to be parented by %p (%s), "
+                     "but parented by %p (%s)", file, line, request, talloc_get_name(request),
                      parent, parent ? talloc_get_name(parent) : "NULL");
 
                fr_log_talloc_report(packet);
@@ -1090,27 +1089,27 @@ static void verify_packet(REQUEST *request, RADIUS_PACKET *packet)
        if (!packet->vps) return;
 
 #ifdef WITH_VERIFY_PTR
-       fr_verify_list(packet, packet->vps);
+       fr_verify_list(file, line, packet, packet->vps);
 #endif
 }
 /*
  *     Catch horrible talloc errors.
  */
-void verify_request(REQUEST *request)
+void verify_request(char const *file, int line, REQUEST *request)
 {
        if (!request) return;
 
        (void) talloc_get_type_abort(request, REQUEST);
 
 #ifdef WITH_VERIFY_PTR
-       fr_verify_list(request, request->config_items);
+       fr_verify_list(file, line, request, request->config_items);
 #endif
 
-       if (request->packet) verify_packet(request, request->packet);
-       if (request->reply) verify_packet(request, request->reply);
+       if (request->packet) verify_packet(file, line, request, request->packet);
+       if (request->reply) verify_packet(file, line, request, request->reply);
 #ifdef WITH_PROXY
-       if (request->proxy) verify_packet(request, request->proxy);
-       if (request->proxy_reply) verify_packet(request, request->proxy_reply);
+       if (request->proxy) verify_packet(file, line, request, request->proxy);
+       if (request->proxy_reply) verify_packet(file, line, request, request->proxy_reply);
 #endif
 
 #ifdef WITH_COA
@@ -1122,7 +1121,7 @@ void verify_request(REQUEST *request)
 
                rad_assert(parent == request);
 
-               verify_request(request->coa);
+               verify_request(file, line, request->coa);
        }
 #endif
 }