Sprinkle VERIFY_REQUEST throughout the state machine
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 17 Jun 2014 10:26:08 +0000 (11:26 +0100)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Tue, 17 Jun 2014 10:26:08 +0000 (11:26 +0100)
src/include/radiusd.h
src/main/process.c

index 1fd09c0..27e9d56 100644 (file)
@@ -189,9 +189,14 @@ typedef            int (*RAD_REQUEST_FUNP)(REQUEST *);
 #define REQUEST_MAX_REGEX (8)
 
 #if defined(WITH_VERIFY_PTR)
-#define VERIFY_REQUEST(_x) (void) talloc_get_type_abort(_x, REQUEST)
+#  define VERIFY_REQUEST(_x) (void) talloc_get_type_abort(_x, REQUEST)
 #else
-#define VERIFY_REQUEST(_x)
+/*
+ *  Even if were building without WITH_VERIFY_PTR
+ *  the pointer must not be NULL when these various macros are used
+ *  so we can add some sneaky asserts.
+ */
+#  define VERIFY_REQUEST(_x) rad_assert(_x)
 #endif
 
 typedef enum {
index 963cb83..792c5d4 100644 (file)
@@ -411,6 +411,8 @@ static void debug_packet(REQUEST *request, RADIUS_PACKET *packet, int direction)
 
 static struct timeval *request_response_window(REQUEST *request)
 {
+       VERIFY_REQUEST(request);
+
        /*
         *      The client hasn't set the response window.  Return
         *      either the home server one, if set, or the global one.
@@ -434,6 +436,8 @@ static int request_init_delay(REQUEST *request)
 {
        struct timeval half_response_window;
 
+       VERIFY_REQUEST(request);
+
        /* Allow client response window to lower initial delay */
        if (timerisset(&request->client->response_window)) {
                half_response_window.tv_sec = request->client->response_window.tv_sec >> 1;
@@ -454,8 +458,10 @@ static int request_init_delay(REQUEST *request)
  */
 static void request_timer(void *ctx)
 {
-       REQUEST *request = ctx;
-       int action = request->timer_action;
+       REQUEST *request = talloc_get_type_abort(ctx, REQUEST);
+       int action;
+
+       action = request->timer_action;
 
        TRACE_STATE_MACHINE;
 
@@ -472,6 +478,8 @@ STATE_MACHINE_DECL(request_done)
        char buffer[128];
 #endif
 
+       VERIFY_REQUEST(request);
+
        TRACE_STATE_MACHINE;
 
 #ifdef WITH_COA
@@ -719,6 +727,8 @@ static void request_cleanup_delay_init(REQUEST *request, struct timeval const *p
 {
        struct timeval now, when;
 
+       VERIFY_REQUEST(request);
+
        if (request->packet->code == PW_CODE_ACCOUNTING_REQUEST) goto done;
 
        if (!request->root->cleanup_delay) goto done;
@@ -767,6 +777,8 @@ static void request_process_timer(REQUEST *request)
        int action = FR_ACTION_TIMER;
 #endif
 
+       VERIFY_REQUEST(request);
+
        TRACE_STATE_MACHINE;
        ASSERT_MASTER;
 
@@ -980,6 +992,8 @@ static void request_queue_or_run(UNUSED REQUEST *request,
        int action = FR_ACTION_TIMER;
 #endif
 
+       VERIFY_REQUEST(request);
+
        TRACE_STATE_MACHINE;
 
        /*
@@ -1050,6 +1064,8 @@ STATE_MACHINE_DECL(request_common)
        char buffer[128];
 #endif
 
+       VERIFY_REQUEST(request);
+
        TRACE_STATE_MACHINE;
        ASSERT_MASTER;
 
@@ -1114,6 +1130,8 @@ STATE_MACHINE_DECL(request_cleanup_delay)
 {
        struct timeval when;
 
+       VERIFY_REQUEST(request);
+
        TRACE_STATE_MACHINE;
        ASSERT_MASTER;
 
@@ -1154,6 +1172,8 @@ STATE_MACHINE_DECL(request_cleanup_delay)
 
 STATE_MACHINE_DECL(request_response_delay)
 {
+       VERIFY_REQUEST(request);
+
        TRACE_STATE_MACHINE;
        ASSERT_MASTER;
 
@@ -1182,10 +1202,12 @@ STATE_MACHINE_DECL(request_response_delay)
 
 static int CC_HINT(nonnull) request_pre_handler(REQUEST *request, UNUSED int action)
 {
-       TRACE_STATE_MACHINE;
-
        int rcode;
 
+       VERIFY_REQUEST(request);
+
+       TRACE_STATE_MACHINE;
+
        if (request->master_state == REQUEST_STOP_PROCESSING) return 0;
 
        /*
@@ -1236,6 +1258,8 @@ STATE_MACHINE_DECL(request_finish)
 {
        VALUE_PAIR *vp;
 
+       VERIFY_REQUEST(request);
+
        TRACE_STATE_MACHINE;
 
        (void) action;  /* -Wunused */
@@ -1416,6 +1440,8 @@ STATE_MACHINE_DECL(request_finish)
 
 STATE_MACHINE_DECL(request_running)
 {
+       VERIFY_REQUEST(request);
+
        TRACE_STATE_MACHINE;
 
        switch (action) {
@@ -1513,6 +1539,8 @@ int request_receive(rad_listen_t *listener, RADIUS_PACKET *packet,
        struct timeval now;
        listen_socket_t *sock = NULL;
 
+       VERIFY_PACKET(packet);
+
        /*
         *      Set the last packet received.
         */
@@ -1783,7 +1811,7 @@ static REQUEST *request_setup(rad_listen_t *listener, RADIUS_PACKET *packet,
  */
 static void tcp_socket_timer(void *ctx)
 {
-       rad_listen_t *listener = ctx;
+       rad_listen_t *listener = talloc_get_type_abort(ctx, rad_listen_t);
        listen_socket_t *sock = listener->data;
        struct timeval end, now;
        char buffer[256];
@@ -1897,7 +1925,7 @@ static void add_jitter(struct timeval *when)
  */
 static int eol_proxy_listener(void *ctx, void *data)
 {
-       rad_listen_t *this = ctx;
+       rad_listen_t *this = talloc_get_type_abort(ctx, rad_listen_t);
        RADIUS_PACKET **proxy_p = data;
        REQUEST *request;
 
@@ -1926,7 +1954,7 @@ static int eol_proxy_listener(void *ctx, void *data)
 
 static int eol_listener(void *ctx, void *data)
 {
-       rad_listen_t *this = ctx;
+       rad_listen_t *this = talloc_get_type_abort(ctx, rad_listen_t);
        RADIUS_PACKET **packet_p = data;
        REQUEST *request;
 
@@ -1951,6 +1979,8 @@ static int eol_listener(void *ctx, void *data)
  */
 static void remove_from_proxy_hash_nl(REQUEST *request, bool yank)
 {
+       VERIFY_REQUEST(request);
+
        if (!request->in_proxy_hash) return;
 
        fr_packet_list_id_free(proxy_list, request->proxy, yank);
@@ -1994,6 +2024,8 @@ static void remove_from_proxy_hash_nl(REQUEST *request, bool yank)
 
 static void remove_from_proxy_hash(REQUEST *request)
 {
+       VERIFY_REQUEST(request);
+
        /*
         *      Check this without grabbing the mutex because it's a
         *      lot faster that way.
@@ -2023,6 +2055,8 @@ static int insert_into_proxy_hash(REQUEST *request)
        int rcode, tries;
        void *proxy_listener;
 
+       VERIFY_REQUEST(request);
+
        rad_assert(request->proxy != NULL);
        rad_assert(request->home_server != NULL);
        rad_assert(proxy_list != NULL);
@@ -2135,6 +2169,8 @@ static int process_proxy_reply(REQUEST *request, RADIUS_PACKET *reply)
        int post_proxy_type = 0;
        VALUE_PAIR *vp;
 
+       VERIFY_REQUEST(request);
+
        /*
         *      There may be a proxy reply, but it may be too late.
         */
@@ -2175,6 +2211,7 @@ static int process_proxy_reply(REQUEST *request, RADIUS_PACKET *reply)
        }
 
        if (reply) {
+               VERIFY_PACKET(reply);
                /*
                 *      Decode the packet.
                 */
@@ -2253,6 +2290,8 @@ int request_proxy_reply(RADIUS_PACKET *packet)
        struct timeval now;
        char buffer[128];
 
+       VERIFY_PACKET(packet);
+
        PTHREAD_MUTEX_LOCK(&proxy_mutex);
        proxy_p = fr_packet_list_find_byreply(proxy_list, packet);
 
@@ -2377,6 +2416,8 @@ static int setup_post_proxy_fail(REQUEST *request)
        DICT_VALUE const *dval = NULL;
        VALUE_PAIR *vp;
 
+       VERIFY_REQUEST(request);
+
        if (request->proxy->code == PW_CODE_ACCESS_REQUEST) {
                dval = dict_valbyname(PW_POST_PROXY_TYPE, 0,
                                      "Fail-Authentication");
@@ -2413,6 +2454,8 @@ static int setup_post_proxy_fail(REQUEST *request)
 
 STATE_MACHINE_DECL(proxy_no_reply)
 {
+       VERIFY_REQUEST(request);
+
        TRACE_STATE_MACHINE;
 
        switch (action) {
@@ -2438,6 +2481,8 @@ STATE_MACHINE_DECL(proxy_no_reply)
 
 STATE_MACHINE_DECL(proxy_running)
 {
+       VERIFY_REQUEST(request);
+
        TRACE_STATE_MACHINE;
 
        switch (action) {
@@ -2472,6 +2517,8 @@ static int request_will_proxy(REQUEST *request)
        REALM *realm = NULL;
        home_pool_t *pool = NULL;
 
+       VERIFY_REQUEST(request);
+
        if (!request->root->proxy_requests) return 0;
        if (request->packet->dst_port == 0) return 0;
        if (request->packet->code == PW_CODE_STATUS_SERVER) return 0;
@@ -2701,6 +2748,8 @@ static int request_proxy(REQUEST *request, int retransmit)
 {
        char buffer[128];
 
+       VERIFY_REQUEST(request);
+
        rad_assert(request->parent == NULL);
        rad_assert(request->home_server != NULL);
 
@@ -2832,6 +2881,8 @@ static int request_proxy_anew(REQUEST *request)
 {
        home_server_t *home;
 
+       VERIFY_REQUEST(request);
+
        /*
         *      Delete the request from the proxy list.
         *
@@ -2902,6 +2953,8 @@ STATE_MACHINE_DECL(request_ping)
        home_server_t *home = request->home_server;
        char buffer[128];
 
+       VERIFY_REQUEST(request);
+
        TRACE_STATE_MACHINE;
        ASSERT_MASTER;
 
@@ -2984,7 +3037,7 @@ STATE_MACHINE_DECL(request_ping)
  */
 static void ping_home_server(void *ctx)
 {
-       home_server_t *home = ctx;
+       home_server_t *home = talloc_get_type_abort(ctx, home_server_t);
        REQUEST *request;
        VALUE_PAIR *vp;
        struct timeval when, now;
@@ -3191,7 +3244,7 @@ static void mark_home_server_zombie(home_server_t *home, struct timeval *now, st
 
 void revive_home_server(void *ctx)
 {
-       home_server_t *home = ctx;
+       home_server_t *home = talloc_get_type_abort(ctx, home_server_t);
        char buffer[128];
 
 #ifdef WITH_TCP
@@ -3269,6 +3322,8 @@ STATE_MACHINE_DECL(proxy_wait_for_reply)
        home_server_t *home = request->home_server;
        char buffer[128];
 
+       VERIFY_REQUEST(request);
+
        TRACE_STATE_MACHINE;
 
        rad_assert(request->packet->code != PW_CODE_STATUS_SERVER);
@@ -3503,7 +3558,8 @@ static void request_coa_originate(REQUEST *request)
        fr_ipaddr_t ipaddr;
        char buffer[256];
 
-       rad_assert(request != NULL);
+       VERIFY_REQUEST(request);
+
        rad_assert(request->coa != NULL);
        rad_assert(request->proxy == NULL);
        rad_assert(!request->in_proxy_hash);
@@ -3712,6 +3768,8 @@ static void coa_timer(REQUEST *request)
        uint32_t delay, frac;
        struct timeval now, when, mrd;
 
+       VERIFY_REQUEST(request);
+
        rad_assert(request->parent == NULL);
 
        if (request->proxy_reply) return request_process_timer(request);
@@ -3833,6 +3891,8 @@ STATE_MACHINE_DECL(coa_wait_for_reply)
 {
        rad_assert(request->parent == NULL);
 
+       VERIFY_REQUEST(request);
+
        TRACE_STATE_MACHINE;
 
        switch (action) {
@@ -3859,6 +3919,9 @@ static void request_coa_separate(REQUEST *request)
 #ifdef DEBUG_STATE_MACHINE
        int action = FR_ACTION_TIMER;
 #endif
+
+       VERIFY_REQUEST(request);
+
        TRACE_STATE_MACHINE;
 
        rad_assert(request->parent != NULL);
@@ -3883,6 +3946,8 @@ STATE_MACHINE_DECL(coa_no_reply)
 {
        char buffer[128];
 
+       VERIFY_REQUEST(request);
+
        TRACE_STATE_MACHINE;
 
        switch (action) {
@@ -3914,6 +3979,8 @@ STATE_MACHINE_DECL(coa_no_reply)
 
 STATE_MACHINE_DECL(coa_running)
 {
+       VERIFY_REQUEST(request);
+
        TRACE_STATE_MACHINE;
 
        switch (action) {
@@ -3954,7 +4021,7 @@ STATE_MACHINE_DECL(coa_running)
  ***********************************************************************/
 static void event_socket_handler(UNUSED fr_event_list_t *xel, UNUSED int fd, void *ctx)
 {
-       rad_listen_t *listener = ctx;
+       rad_listen_t *listener = talloc_get_type_abort(ctx, rad_listen_t);
 
        rad_assert(xel == el);
 
@@ -3986,7 +4053,7 @@ static void event_socket_handler(UNUSED fr_event_list_t *xel, UNUSED int fd, voi
 static void event_poll_detail(void *ctx)
 {
        int delay;
-       rad_listen_t *this = ctx;
+       rad_listen_t *this = talloc_get_type_abort(ctx, rad_listen_t);
        struct timeval when, now;
        listen_detail_t *detail = this->data;
 
@@ -4062,7 +4129,7 @@ static void event_status(struct timeval *wake)
 #ifdef WITH_TCP
 static void listener_free_cb(void *ctx)
 {
-       rad_listen_t *this = ctx;
+       rad_listen_t *this = talloc_get_type_abort(ctx, rad_listen_t);
        char buffer[1024];
 
        if (this->count > 0) {
@@ -4708,6 +4775,8 @@ static int proxy_delete_cb(UNUSED void *ctx, void *data)
 {
        REQUEST *request = fr_packet2myptr(REQUEST, proxy, data);
 
+       VERIFY_REQUEST(request);
+
        request->master_state = REQUEST_STOP_PROCESSING;
 
 #ifdef HAVE_PTHREAD_H
@@ -4740,6 +4809,8 @@ static int request_delete_cb(UNUSED void *ctx, void *data)
 {
        REQUEST *request = fr_packet2myptr(REQUEST, packet, data);
 
+       VERIFY_REQUEST(request);
+
        request->master_state = REQUEST_STOP_PROCESSING;
 
        /*