import from HEAD:
authorfcusack <fcusack>
Thu, 9 Feb 2006 23:28:46 +0000 (23:28 +0000)
committerfcusack <fcusack>
Thu, 9 Feb 2006 23:28:46 +0000 (23:28 +0000)
otp_authenticate(): malloc raw_state before using it

1  2 
src/modules/rlm_otp/otp_rlm.c

@@@ -44,7 -44,7 +44,7 @@@
  
  #include "otp.h"
  #ifdef FREERADIUS
 -#include <freeradius-devel/modules.h>
 +#include <modules.h>
  #endif
  
  static const char rcsid[] = "$Id$";
@@@ -315,7 -315,7 +315,7 @@@ otp_authorize(void *instance, REQUEST *
      auth_type_found = 0;
      if ((vp = pairfind(request->config_items, PW_AUTHTYPE)) != NULL) {
        auth_type_found = 1;
 -      if (strcmp(vp->vp_strvalue, inst->name))
 +      if (strcmp(vp->strvalue, inst->name))
          return RLM_MODULE_NOOP;
      }
    }
@@@ -455,7 -455,7 +455,7 @@@ otp_authenticate(void *instance, REQUES
              log_prefix, __func__);
      return RLM_MODULE_INVALID;
    }
 -  username = request->username->vp_strvalue;
 +  username = request->username->strvalue;
  
    if ((data.pwattr = otp_pwe_present(request, log_prefix)) == 0) {
      otp_log(OTP_LOG_AUTH, "%s: %s: Attribute \"User-Password\" "
           * Verify the state.
           */
  
-         /* ASCII decode */
          rad_state = rad_malloc(e_length + 1);
 -        (void) memcpy(rad_state, vp->vp_strvalue, vp->length);
+         raw_state = rad_malloc(e_length / 2);
+         /* ASCII decode */
 +        (void) memcpy(rad_state, vp->strvalue, vp->length);
          rad_state[e_length] = '\0';
          (void) otp_keystring2keyblock(rad_state, raw_state);
          free(rad_state);
          
          /* extract data from State */
-         raw_state = rad_malloc(e_length / 2);
          (void) memcpy(challenge, raw_state, inst->chal_len);
          (void) memcpy(&sflags, raw_state + inst->chal_len, 4);
          (void) memcpy(&then, raw_state + inst->chal_len + 4, 4);
            return RLM_MODULE_FAIL;
          }
          /* compare generated state against returned state to verify hmac */
 -        if (memcmp(state, vp->vp_strvalue, vp->length)) {
 +        if (memcmp(state, vp->strvalue, vp->length)) {
            otp_log(OTP_LOG_AUTH, "%s: %s: bad state for [%s]: hmac",
                    log_prefix, __func__, username);
            free(state);
@@@ -584,10 -585,11 +585,10 @@@ otp_detach(void *instance
   *    is single-threaded.
   */
  module_t rlm_otp = {
 -  RLM_MODULE_INIT,
    "otp",
    RLM_TYPE_THREAD_SAFE,               /* type */
 +  NULL,                               /* initialization */
    otp_instantiate,            /* instantiation */
 -  otp_detach,                 /* detach */
    {
      otp_authenticate,         /* authentication */
      otp_authorize,            /* authorization */
      NULL,                     /* post-proxy */
      NULL                      /* post-auth */
    },
 +  otp_detach,                 /* detach */
 +  NULL,                               /* destroy */
  };