Fixes from clang / scan-build
authorAlan T. DeKok <aland@freeradius.org>
Thu, 7 Oct 2010 08:30:12 +0000 (10:30 +0200)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 7 Oct 2010 08:30:12 +0000 (10:30 +0200)
Nothing to see here, folks.  Move along.

16 files changed:
src/lib/packet.c
src/lib/print.c
src/lib/radius.c
src/lib/token.c
src/main/event.c
src/main/radclient.c
src/modules/rlm_eap/libeap/eap_tls.c
src/modules/rlm_eap/rlm_eap.c
src/modules/rlm_eap/types/rlm_eap_leap/eap_leap.c
src/modules/rlm_eap/types/rlm_eap_peap/peap.c
src/modules/rlm_eap/types/rlm_eap_ttls/ttls.c
src/modules/rlm_mschap/rlm_mschap.c
src/modules/rlm_mschap/smbdes.c
src/modules/rlm_mschap/smbdes.h
src/modules/rlm_otp/otp_pw_valid.c
src/modules/rlm_realm/rlm_realm.c

index 15d5bc9..0091192 100644 (file)
@@ -445,7 +445,6 @@ int fr_packet_list_socket_add(fr_packet_list_t *pl, int sockfd, int proto,
        do {
                if (pl->sockets[i].sockfd == -1) {
                        ps =  &pl->sockets[i];
-                       start = i;
                        break;
                }
 
index 9b51cbb..2c14c22 100644 (file)
@@ -431,7 +431,6 @@ int vp_prints(char *out, size_t outlen, VALUE_PAIR *vp)
        if (!vp) return 0;
 
        name = vp->name;
-       len = 0;
 
        if (!name || !*name) {
                if (!vp_print_name(namebuf, sizeof(namebuf), vp->attribute, vp->attribute)) {
index 359756a..439feec 100644 (file)
@@ -936,7 +936,6 @@ static int rad_vp2extended(const RADIUS_PACKET *packet,
 
        if (vp->flags.extended) {
                ptr[2] = (attribute & 0xff00) >> 8;
-               len++;
 
        } else if (vp->flags.extended_flags) {
                if (room < 4) return 0;
@@ -944,8 +943,6 @@ static int rad_vp2extended(const RADIUS_PACKET *packet,
                ptr[1] = 4;
                ptr[2] = (attribute & 0xff00) >> 8;
                ptr[3] = 0;
-
-               len += 2;
        }
 
        /*
@@ -1101,7 +1098,7 @@ static int rad_encode_wimax(const RADIUS_PACKET *packet,
 {
        int len, redo;
        uint32_t lvalue;
-       uint8_t *ptr = start, *vsa = start;
+       uint8_t *ptr, *vsa;
        uint32_t maxattr;
        VALUE_PAIR *vp = reply;
 
@@ -3705,7 +3702,7 @@ void fr_rand_seed(const void *data, size_t size)
                        size_t total;
                        ssize_t this;
 
-                       total = this = 0;
+                       total = 0;
                        while (total < sizeof(fr_rand_pool.randrsl)) {
                                this = read(fd, fr_rand_pool.randrsl,
                                            sizeof(fr_rand_pool.randrsl) - total);
index e161f78..47fb90a 100644 (file)
@@ -75,7 +75,6 @@ static FR_TOKEN getthing(const char **ptr, char *buf, int buflen, int tok,
        char *s;
        const char *p;
        int     quote, end = 0;
-       int     escape;
        unsigned int    x;
        const FR_NAME_NUMBER*t;
        FR_TOKEN rcode;
@@ -116,7 +115,6 @@ static FR_TOKEN getthing(const char **ptr, char *buf, int buflen, int tok,
                p++;
        }
        s = buf;
-       escape = 0;
 
        while (*p && buflen-- > 1) {
                if (quote && (*p == '\\')) {
@@ -238,7 +236,11 @@ FR_TOKEN gettoken(const char **ptr, char *buf, int buflen)
  */
 FR_TOKEN getstring(const char **ptr, char *buf, int buflen)
 {
-       const char *p = *ptr;
+       const char *p;
+
+       if (!ptr || !*ptr || !buf) return T_OP_INVALID;
+       
+       p = *ptr;
 
        while (p && (isspace((int)*p))) p++;
 
index a67d90b..78bb220 100644 (file)
@@ -3568,7 +3568,7 @@ int event_new_fd(rad_listen_t *this)
                }               
 #ifdef WITH_PROXY
                else {
-                       int count = this->count;
+                       int count;
 
                        /*
                         *      Duplicate code
index 42cb088..a14801d 100644 (file)
@@ -617,7 +617,7 @@ static int send_one_packet(radclient_t *radclient)
                                                radclient->request->id, vp);
                                vp->length = 17;
 
-                       } else if ((vp = pairfind(radclient->request->vps, PW_MSCHAP_PASSWORD, 0)) != NULL) {
+                       } else if (pairfind(radclient->request->vps, PW_MSCHAP_PASSWORD, 0) != NULL) {
                                mschapv1_encode(&radclient->request->vps,
                                                radclient->password);
                        } else if (fr_debug_flag) {
index 1c15db1..1a1ad21 100644 (file)
@@ -839,6 +839,8 @@ eaptls_status_t eaptls_process(EAP_HANDLER *handler)
        eaptls_status_t status;
        REQUEST *request = handler->request;
 
+       rad_assert(request != NULL);
+
        RDEBUG2("processing EAP-TLS");
        if (handler->certs) pairadd(&request->packet->vps,
                                    paircopy(handler->certs));
index 9bcda21..e6399ba 100644 (file)
@@ -108,7 +108,7 @@ static int eap_handler_cmp(const void *a, const void *b)
  */
 static int eap_handler_ptr_cmp(const void *a, const void *b)
 {
-  return (a - b);
+  return (((uint8_t *) a) - ((uint8_t *) b));
 }
 
 
index ae953e3..edf46c0 100644 (file)
@@ -365,7 +365,6 @@ LEAP_PACKET *eapleap_stage6(LEAP_PACKET *packet, REQUEST *request,
        memcpy(p, session->peer_challenge, 8); /* PC */
        p += 8;
        memcpy(p, session->peer_response, 24); /* PR */
-       p += 24;
 
        /*
         *      These 16 bytes are the session key to use.
index 9ef8836..a0b843c 100644 (file)
@@ -240,6 +240,8 @@ static VALUE_PAIR *eap2vp(REQUEST *request, EAP_DS *eap_ds,
  */
 static int vp2eap(REQUEST *request, tls_session_t *tls_session, VALUE_PAIR *vp)
 {
+       rad_assert(vp != NULL);
+
        /*
         *      Skip the id, code, and length.  Just write the EAP
         *      type & data to the client.
@@ -448,6 +450,7 @@ static int eappeap_postproxy(EAP_HANDLER *handler, void *data)
        tls_session_t *tls_session = (tls_session_t *) data;
        REQUEST *fake, *request = handler->request;
 
+       rad_assert(request != NULL);
        RDEBUG2("Passing reply from proxy back into the tunnel.");
 
        /*
@@ -488,7 +491,7 @@ static int eappeap_postproxy(EAP_HANDLER *handler, void *data)
                 */
                fake->options &= ~RAD_REQUEST_OPTION_PROXY_EAP;
                RDEBUG2("Passing reply back for EAP-MS-CHAP-V2");
-               rcode = module_post_proxy(0, fake);
+               module_post_proxy(0, fake);
 
                /*
                 *      FIXME: If rcode returns fail, do something
@@ -644,6 +647,8 @@ int eappeap_process(EAP_HANDLER *handler, tls_session_t *tls_session)
        REQUEST *request = handler->request;
        EAP_DS *eap_ds = handler->eap_ds;
 
+       rad_assert(request != NULL);
+
        /*
         *      Just look at the buffer directly, without doing
         *      record_minus.  This lets us avoid another data copy.
index c3fde1c..fc2aca3 100644 (file)
@@ -618,6 +618,8 @@ static int process_reply(EAP_HANDLER *handler, tls_session_t *tls_session,
        ttls_tunnel_t *t = tls_session->opaque;
 
        handler = handler;      /* -Wunused */
+       rad_assert(request != NULL);
+       rad_assert(handler->request == request);
 
        /*
         *      If the response packet was Access-Accept, then
@@ -789,6 +791,7 @@ static int eapttls_postproxy(EAP_HANDLER *handler, void *data)
        tls_session_t *tls_session = (tls_session_t *) data;
        REQUEST *fake, *request = handler->request;
 
+       rad_assert(request != NULL);
        RDEBUG("Passing reply from proxy back into the tunnel.");
 
        /*
@@ -929,6 +932,8 @@ int eapttls_process(EAP_HANDLER *handler, tls_session_t *tls_session)
        size_t data_len;
        REQUEST *request = handler->request;
 
+       rad_assert(request != NULL);
+
        /*
         *      Just look at the buffer directly, without doing
         *      record_minus.
index 353192a..b767835 100644 (file)
@@ -663,6 +663,8 @@ static int do_mschap(rlm_mschap_t *inst,
 {
        uint8_t         calculated[24];
 
+       rad_assert(request != NULL);
+
        /*
         *      Do normal authentication.
         */
@@ -675,7 +677,7 @@ static int do_mschap(rlm_mschap_t *inst,
                        return -1;
                }
 
-               smbdes_mschap(password->vp_strvalue, challenge, calculated);
+               smbdes_mschap(password->vp_octets, challenge, calculated);
                if (memcmp(response, calculated, 24) != 0) {
                        return -1;
                }
index cb50369..fac766d 100644 (file)
@@ -336,7 +336,7 @@ void smbdes_lmpwdhash(const char *password, uint8_t *lmhash)
  *
  *     The win_password MUST be exactly 16 bytes long.
  */
-void smbdes_mschap(const char *win_password,
+void smbdes_mschap(const uint8_t win_password[16],
                 const uint8_t *challenge, uint8_t *response)
 {
        uint8_t p21[21];
index 615de87..56ca71f 100644 (file)
@@ -7,7 +7,7 @@
 RCSIDH(smbdes_h, "$Id$")
 
 void smbdes_lmpwdhash(const char *password, uint8_t *lmhash);
-void smbdes_mschap(const char *win_password,
+void smbdes_mschap(const uint8_t win_password[16],
                 const uint8_t *challenge, uint8_t *response);
 
 #endif /*_SMBDES_H*/
index 93392fb..204e20f 100644 (file)
@@ -206,8 +206,7 @@ retry:
   if (!fdp || fdp->fd == -1)
     return -1;
 
-  if (otp_write(fdp, (const char *) request, sizeof(*request)) != 0) {
-    if (rc == 0)
+  if ((rc = otp_write(fdp, (const char *) request, sizeof(*request))) != sizeof(*request)) {    if (rc == 0)
       goto retry;      /* otpd disconnect */   /*TODO: pause */
     else
       return -1;
index e960a26..6006769 100644 (file)
@@ -60,7 +60,7 @@ static int check_for_realm(void *instance, REQUEST *request, REALM **returnrealm
 {
        char namebuf[MAX_STRING_LEN];
        char *username;
-       char *realmname = NULL;
+       const char *realmname = NULL;
        char *ptr;
        VALUE_PAIR *vp;
        REALM *realm;
@@ -111,10 +111,10 @@ static int check_for_realm(void *instance, REQUEST *request, REALM **returnrealm
        case REALM_FORMAT_SUFFIX:
 
          /* DEBUG2("  rlm_realm: Checking for suffix after \"%c\"", inst->delim[0]); */
-               realmname = strrchr(username, inst->delim[0]);
-               if (realmname) {
-                       *realmname = '\0';
-                       realmname++;
+               ptr = strrchr(username, inst->delim[0]);
+               if (ptr) {
+                       *ptr = '\0';
+                       realmname = ptr + 1;
                }
                break;