Various scan-build fixes
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 1 May 2014 12:51:07 +0000 (13:51 +0100)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Fri, 2 May 2014 13:57:55 +0000 (14:57 +0100)
src/include/libradius.h
src/include/radiusd.h
src/main/threads.c
src/modules/rlm_cache/rlm_cache.c
src/modules/rlm_eap/types/rlm_eap_peap/peap.c
src/modules/rlm_eap/types/rlm_eap_ttls/ttls.c
src/modules/rlm_ldap/attrmap.c
src/modules/rlm_ldap/rlm_ldap.c
src/modules/rlm_linelog/rlm_linelog.c
src/modules/rlm_mschap/rlm_mschap.c
src/modules/rlm_sqlippool/rlm_sqlippool.c

index 84d169a..ab751b3 100644 (file)
@@ -577,7 +577,10 @@ VALUE_PAIR *_fr_cursor_init(vp_cursor_t *cursor, VALUE_PAIR const * const *node)
 void           fr_cursor_copy(vp_cursor_t *out, vp_cursor_t *in);
 VALUE_PAIR     *fr_cursor_first(vp_cursor_t *cursor);
 VALUE_PAIR     *fr_cursor_next_by_num(vp_cursor_t *cursor, unsigned int attr, unsigned int vendor, int8_t tag);
-VALUE_PAIR     *fr_cursor_next_by_da(vp_cursor_t *cursor, DICT_ATTR const *da, int8_t tag);
+
+VALUE_PAIR     *fr_cursor_next_by_da(vp_cursor_t *cursor, DICT_ATTR const *da, int8_t tag)
+               CC_HINT(nonnull);
+
 VALUE_PAIR     *fr_cursor_next(vp_cursor_t *cursor);
 VALUE_PAIR     *fr_cursor_current(vp_cursor_t *cursor);
 void           fr_cursor_insert(vp_cursor_t *cursor, VALUE_PAIR *vp);
index 08b1dce..87c34dd 100644 (file)
@@ -595,7 +595,8 @@ int radius_readfrom_program(REQUEST *request, int fd, pid_t pid, int timeout,
 int radius_exec_program(REQUEST *request, char const *cmd, bool exec_wait, bool shell_escape,
                        char *user_msg, size_t msg_len, int timeout,
                        VALUE_PAIR *input_pairs, VALUE_PAIR **output_pairs);
-void exec_trigger(REQUEST *request, CONF_SECTION *cs, char const *name, int quench);
+void exec_trigger(REQUEST *request, CONF_SECTION *cs, char const *name, int quench)
+     CC_HINT(nonnull (3));
 
 /* valuepair.c */
 int paircompare_register(DICT_ATTR const *attribute, DICT_ATTR const *from,
@@ -628,11 +629,15 @@ void vmodule_failure_msg(REQUEST *request, char const *fmt, va_list ap) CC_HINT(
 typedef size_t (*RADIUS_ESCAPE_STRING)(REQUEST *, char *out, size_t outlen, char const *in, void *arg);
 
 ssize_t radius_xlat(char *out, size_t outlen, REQUEST *request, char const *fmt, RADIUS_ESCAPE_STRING escape,
-                   void *escape_ctx);
+                   void *escape_ctx)
+       CC_HINT(nonnull (1, 3, 4));
 
-ssize_t radius_axlat(char **out, REQUEST *request, char const *fmt, RADIUS_ESCAPE_STRING escape,
-                         void *escape_ctx);
-ssize_t radius_axlat_struct(char **out, REQUEST *request, xlat_exp_t const *xlat, RADIUS_ESCAPE_STRING escape, void *ctx);
+ssize_t radius_axlat(char **out, REQUEST *request, char const *fmt, RADIUS_ESCAPE_STRING escape, void *escape_ctx)
+       CC_HINT(nonnull (1, 2, 3));
+
+ssize_t radius_axlat_struct(char **out, REQUEST *request, xlat_exp_t const *xlat, RADIUS_ESCAPE_STRING escape,
+                           void *ctx)
+       CC_HINT(nonnull (1, 2, 3));
 
 typedef ssize_t (*RAD_XLAT_FUNC)(void *instance, REQUEST *, char const *, char *, size_t);
 int            xlat_register(char const *module, RAD_XLAT_FUNC func, RADIUS_ESCAPE_STRING escape,
@@ -642,15 +647,15 @@ ssize_t           xlat_fmt_to_ref(uint8_t const **out, REQUEST *request, char const *fmt)
 void           xlat_free(void);
 
 /* threads.c */
-extern         int thread_pool_init(CONF_SECTION *cs, bool *spawn_flag);
-extern         void thread_pool_stop(void);
-extern         int thread_pool_addrequest(REQUEST *, RAD_REQUEST_FUNP);
-extern         pid_t rad_fork(void);
-extern         pid_t rad_waitpid(pid_t pid, int *status);
-extern   int total_active_threads(void);
-extern   void thread_pool_lock(void);
-extern   void thread_pool_unlock(void);
-extern         void thread_pool_queue_stats(int array[RAD_LISTEN_MAX], int pps[2]);
+extern int thread_pool_init(CONF_SECTION *cs, bool *spawn_flag);
+extern void thread_pool_stop(void);
+extern int thread_pool_addrequest(REQUEST *, RAD_REQUEST_FUNP);
+extern pid_t rad_fork(void);
+extern pid_t rad_waitpid(pid_t pid, int *status);
+extern int total_active_threads(void);
+extern void thread_pool_lock(void);
+extern void thread_pool_unlock(void);
+extern void thread_pool_queue_stats(int array[RAD_LISTEN_MAX], int pps[2]);
 
 #ifndef HAVE_PTHREAD_H
 #define rad_fork(n) fork()
index 4c9da08..1d3c958 100644 (file)
@@ -1430,12 +1430,12 @@ void exec_trigger(REQUEST *request, CONF_SECTION *cs, char const *name, int quen
 
        ci = cf_reference_item(subcs, mainconfig.config, attr);
        if (!ci) {
-               RDEBUG3("No such item in trigger section: %s", attr);
+               EDEBUG3("No such item in trigger section: %s", attr);
                return;
        }
 
        if (!cf_item_is_pair(ci)) {
-               RDEBUG2("Trigger is not a configuration variable: %s", attr);
+               EDEBUG2("Trigger is not a configuration variable: %s", attr);
                return;
        }
 
@@ -1444,7 +1444,7 @@ void exec_trigger(REQUEST *request, CONF_SECTION *cs, char const *name, int quen
 
        value = cf_pair_value(cp);
        if (!value) {
-               RDEBUG2("Trigger has no value: %s", name);
+               EDEBUG2("Trigger has no value: %s", name);
                return;
        }
 
@@ -1482,6 +1482,6 @@ void exec_trigger(REQUEST *request, CONF_SECTION *cs, char const *name, int quen
                }
        }
 
-       RDEBUG("Trigger %s -> %s", name, value);
+       DEBUG("Trigger %s -> %s", name, value);
        radius_exec_program(request, value, false, true, NULL, 0, EXEC_TIMEOUT, vp, NULL);
 }
index 03eb20c..f6b80e6 100644 (file)
@@ -351,6 +351,8 @@ static rlm_cache_entry_t *cache_add(rlm_cache_t *inst, REQUEST *request,
 
                                from = NULL;
                                da = map->src->vpt_da;
+                               rad_assert(da != NULL);
+
                                context = request;
                                if (radius_request(&context, map->src->vpt_request) == 0) {
                                        from = radius_list(context, map->src->vpt_list);
@@ -363,7 +365,7 @@ static rlm_cache_entry_t *cache_add(rlm_cache_t *inst, REQUEST *request,
                                if (!from) continue;
 
                                fr_cursor_init(&cursor, from);
-                               found = fr_cursor_next_by_num(&cursor, da->attr, da->vendor, TAG_ANY);
+                               found = fr_cursor_next_by_da(&cursor, da, TAG_ANY);
                                if (!found) {
                                        RWDEBUG("\"%s\" not found, skipping",
                                               map->src->name);
@@ -407,7 +409,7 @@ static rlm_cache_entry_t *cache_add(rlm_cache_t *inst, REQUEST *request,
                                                        radius_pairmove(request, to_req, vp, false);
 
                                                }
-                                       } while ((found = fr_cursor_next_by_num(&cursor, da->attr, da->vendor, TAG_ANY)));
+                                       } while ((found = fr_cursor_next_by_da(&cursor, da, TAG_ANY)));
                                        break;
 
                                default:
index d010030..38557e0 100644 (file)
@@ -416,8 +416,8 @@ static int eappeap_check_tlv(REQUEST *request, uint8_t const *data,
 /*
  *     Use a reply packet to determine what to do.
  */
-static int process_reply(eap_handler_t *handler, tls_session_t *tls_session,
-                        REQUEST *request, RADIUS_PACKET *reply)
+static int CC_HINT(nonnull) process_reply(eap_handler_t *handler, tls_session_t *tls_session,
+                                         REQUEST *request, RADIUS_PACKET *reply)
 {
        int rcode = RLM_MODULE_REJECT;
        VALUE_PAIR *vp;
index f0e174d..1e8300f 100644 (file)
@@ -805,9 +805,7 @@ static int CC_HINT(nonnull) eapttls_postproxy(eap_handler_t *handler, void *data
        /*
         *      Do the callback, if it exists, and if it was a success.
         */
-       if (fake &&
-           handler->request->proxy_reply &&
-           (handler->request->proxy_reply->code == PW_CODE_AUTHENTICATION_ACK)) {
+       if (fake && (handler->request->proxy_reply->code == PW_CODE_AUTHENTICATION_ACK)) {
                /*
                 *      Terrible hacks.
                 */
@@ -872,8 +870,7 @@ static int CC_HINT(nonnull) eapttls_postproxy(eap_handler_t *handler, void *data
        /*
         *      Process the reply from the home server.
         */
-       rcode = process_reply(handler, tls_session, handler->request,
-                             handler->request->proxy_reply);
+       rcode = process_reply(handler, tls_session, handler->request, handler->request->proxy_reply);
 
        /*
         *      The proxy code uses the reply from the home server as
index 5341e56..9eb2b4e 100644 (file)
@@ -261,7 +261,7 @@ int rlm_ldap_map_xlat(REQUEST *request, value_pair_map_t const *maps, rlm_ldap_m
                        ssize_t len;
                        char *exp = NULL;
 
-                       len = radius_xlat(exp, 0, request, map->src->name, NULL, NULL);
+                       len = radius_axlat(&exp, request, map->src->name, NULL, NULL);
                        if (len < 0) {
                                RDEBUG("Expansion of LDAP attribute \"%s\" failed", map->src->name);
 
index be5a4be..41dd33e 100644 (file)
@@ -1131,7 +1131,7 @@ static rlm_rcode_t user_modify(ldap_instance_t *inst, REQUEST *request, ldap_acc
                } else if (do_xlat) {
                        char *exp = NULL;
 
-                       if (radius_xlat(exp, 0, request, value, NULL, NULL) <= 0) {
+                       if (radius_axlat(&exp, request, value, NULL, NULL) <= 0) {
                                RDEBUG("Skipping attribute \"%s\"", attr);
 
                                talloc_free(exp);
index 73007f3..f168054 100644 (file)
@@ -95,7 +95,10 @@ static int mod_instantiate(CONF_SECTION *conf, void *instance)
 {
        rlm_linelog_t *inst = instance;
 
-       rad_assert(inst->filename && *inst->filename);
+       if (!inst->filename) {
+               cf_log_err_cs(conf, "No value provided for 'filename'");
+               return -1;
+       }
 
 #ifndef HAVE_SYSLOG_H
        if (strcmp(inst->filename, "syslog") == 0) {
@@ -211,14 +214,15 @@ static rlm_rcode_t CC_HINT(nonnull) mod_do_linelog(void *instance, REQUEST *requ
        char *endptr;
 #endif
 
+       line[0] = '\0';
+
        if (inst->reference) {
                CONF_ITEM *ci;
                CONF_PAIR *cp;
 
                p = line + 1;
 
-               if (radius_xlat(p, sizeof(line) - 2, request, inst->reference, linelog_escape_func,
-                   NULL) < 0) {
+               if (radius_xlat(p, sizeof(line) - 2, request, inst->reference, linelog_escape_func, NULL) < 0) {
                        return RLM_MODULE_FAIL;
                }
 
@@ -304,7 +308,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_do_linelog(void *instance, REQUEST *requ
        /*
         *      FIXME: Check length.
         */
-       if (radius_xlat(line, sizeof(line) - 1, request, value, linelog_escape_func, NULL) < 0) {
+       if (value && (radius_xlat(line, sizeof(line) - 1, request, value, linelog_escape_func, NULL) < 0)) {
                if (fd > -1) {
                        fr_logfile_close(inst->lf, fd);
                }
index 2a40524..29e5f72 100644 (file)
@@ -677,16 +677,16 @@ static int write_all(int fd, char const *buf, int len) {
  * Perform an MS-CHAP2 password change
  */
 
-static int CC_HINT(nonnull) do_mschap_cpw(rlm_mschap_t *inst,
-                                         REQUEST *request,
+static int CC_HINT(nonnull (1, 2, 4, 5)) do_mschap_cpw(rlm_mschap_t *inst,
+                                                      REQUEST *request,
 #ifdef HAVE_OPENSSL_CRYPTO_H
-                                         VALUE_PAIR *nt_password,
+                                                      VALUE_PAIR *nt_password,
 #else
-                                         UNUSED VALUE_PAIR *nt_password,
+                                                      UNUSED VALUE_PAIR *nt_password,
 #endif
-                                         uint8_t *new_nt_password,
-                                         uint8_t *old_nt_hash,
-                                         int do_ntlm_auth)
+                                                      uint8_t *new_nt_password,
+                                                      uint8_t *old_nt_hash,
+                                                      bool do_ntlm_auth)
 {
        if (inst->ntlm_cpw && do_ntlm_auth) {
                /*
@@ -1037,11 +1037,11 @@ ntlm_auth_err:
  *     authentication is in one place, and we can perhaps later replace
  *     it with code to call winbindd, or something similar.
  */
-static int CC_HINT(nonnull) do_mschap(rlm_mschap_t *inst, REQUEST *request, VALUE_PAIR *password,
-                                     uint8_t const *challenge, uint8_t const *response,
-                                     uint8_t *nthashhash, int do_ntlm_auth)
+static int CC_HINT(nonnull (1, 2, 4, 5 ,6)) do_mschap(rlm_mschap_t *inst, REQUEST *request, VALUE_PAIR *password,
+                                                     uint8_t const *challenge, uint8_t const *response,
+                                                     uint8_t *nthashhash, bool do_ntlm_auth)
 {
-       uint8_t         calculated[24];
+       uint8_t calculated[24];
 
        /*
         *      Do normal authentication.
@@ -1326,7 +1326,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_authenticate(void * instance, REQUEST *r
        uint8_t *p;
        char const *username_string;
        int chap = 0;
-       int             do_ntlm_auth;
+       bool do_ntlm_auth;
 
        /*
         *      If we have ntlm_auth configured, use it unless told
@@ -1340,7 +1340,7 @@ static rlm_rcode_t CC_HINT(nonnull) mod_authenticate(void * instance, REQUEST *r
         */
        if (do_ntlm_auth) {
                VALUE_PAIR *vp = pairfind(request->config_items, PW_MS_CHAP_USE_NTLM_AUTH, 0, TAG_ANY);
-               if (vp) do_ntlm_auth = vp->vp_integer;
+               if (vp) do_ntlm_auth = (vp->vp_integer > 0);
        }
 
        /*
@@ -1521,11 +1521,12 @@ static rlm_rcode_t CC_HINT(nonnull) mod_authenticate(void * instance, REQUEST *r
                 * 2 octets  - flags (ignored)
                 */
 
-               memcpy(old_nt_encrypted, cpw->vp_octets+2, sizeof(old_nt_encrypted));
+               memcpy(old_nt_encrypted, cpw->vp_octets + 2, sizeof(old_nt_encrypted));
 
                RDEBUG2("Password change payload valid");
 
                /* perform the actual password change */
+               rad_assert(nt_password);
                if (do_mschap_cpw(inst, request, nt_password, new_nt_encrypted, old_nt_encrypted, do_ntlm_auth) < 0) {
                        char buffer[128];
 
index 009e174..bc3de65 100644 (file)
@@ -346,9 +346,9 @@ static int sqlippool_command(char const * fmt, rlm_sql_handle_t * handle, rlm_sq
 /*
  * Query the database expecting a single result row
  */
-static int CC_HINT(nonnull (1,3,4,5)) sqlippool_query1(char *out, int outlen, char const *fmt,
-                                                      rlm_sql_handle_t *handle, rlm_sqlippool_t *data,
-                                                      REQUEST *request, char *param, int param_len)
+static int CC_HINT(nonnull (1, 3, 4, 5)) sqlippool_query1(char *out, int outlen, char const *fmt,
+                                                         rlm_sql_handle_t *handle, rlm_sqlippool_t *data,
+                                                         REQUEST *request, char *param, int param_len)
 {
        char query[MAX_QUERY_LEN];
        char *expanded = NULL;