Move more things to doing pairmemcpy instead of calling individual functions
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sun, 6 Apr 2014 19:51:01 +0000 (20:51 +0100)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Sun, 6 Apr 2014 21:25:20 +0000 (22:25 +0100)
src/lib/radius.c
src/lib/valuepair.c
src/main/evaluate.c
src/main/process.c
src/modules/rlm_preprocess/rlm_preprocess.c

index 1c35052..8add96b 100644 (file)
@@ -3751,8 +3751,7 @@ static ssize_t data2vp(RADIUS_PACKET *packet,
                break;
 
        case PW_TYPE_OCTETS:
-               vp->vp_octets = talloc_memdup(vp, data, vp->length);
-               talloc_set_type(vp->vp_octets, uint8_t);
+               pairmemcpy(vp, data, vp->length);
                break;
 
        case PW_TYPE_ABINARY:
index e55f519..8cb849e 100644 (file)
@@ -1435,8 +1435,7 @@ bool pairparsevalue(VALUE_PAIR *vp, char const *value)
                        }
                        vp->vp_octets = us;
                } else {
-                       pairstrcpy(vp, value);
-                       talloc_set_type(vp->vp_octets, uint8_t);        /* fixup type */
+                       pairmemcpy(vp, (const uint8_t *) value, strlen(value));
                }
                break;
 
index 59150d4..b40e5ab 100644 (file)
@@ -343,14 +343,10 @@ static bool do_cast_copy(VALUE_PAIR *dst, VALUE_PAIR const *src)
 
        if (dst->da->type == PW_TYPE_OCTETS) {
                if (src->da->type == PW_TYPE_STRING) {
-                       dst->vp_octets = talloc_memdup(dst, src->vp_strvalue, src->length);
-                       talloc_set_type(dst->vp_octets, uint8_t);
+                       pairmemcpy(dst, src->vp_octets, src->length);   /* Copy embedded NULLs */
                } else {
-                       dst->vp_octets = talloc_memdup(dst, &src->data, src->length);
-                       talloc_set_type(dst->vp_octets, uint8_t);
+                       pairmemcpy(dst, (uint8_t const *) &src->data, src->length);
                }
-
-               dst->length = src->length;
                return true;
        }
 
index 3d4b538..74e4477 100644 (file)
@@ -430,7 +430,7 @@ STATE_MACHINE_DECL(request_done)
        if (request->parent && (request->parent->coa == request)) {
                request->parent->coa = NULL;
        }
-       
+
 #endif
 
        /*
@@ -2458,22 +2458,15 @@ static int request_will_proxy(REQUEST *request)
        if ((request->packet->code == PW_CODE_AUTHENTICATION_REQUEST) &&
            pairfind(request->proxy->vps, PW_CHAP_PASSWORD, 0, TAG_ANY) &&
            pairfind(request->proxy->vps, PW_CHAP_CHALLENGE, 0, TAG_ANY) == NULL) {
-               uint8_t *p;
-               vp = radius_paircreate(request, &request->proxy->vps,
-                                      PW_CHAP_CHALLENGE, 0);
-               vp->length = sizeof(request->packet->vector);
-               vp->vp_octets = p = talloc_array(vp, uint8_t, vp->length);
-
-               memcpy(p, request->packet->vector,
-                      sizeof(request->packet->vector));
+               vp = radius_paircreate(request, &request->proxy->vps, PW_CHAP_CHALLENGE, 0);
+               pairmemcpy(vp, request->packet->vector, sizeof(request->packet->vector));
        }
 
        /*
         *      The RFC's say we have to do this, but FreeRADIUS
         *      doesn't need it.
         */
-       vp = radius_paircreate(request, &request->proxy->vps,
-                              PW_PROXY_STATE, 0);
+       vp = radius_paircreate(request, &request->proxy->vps, PW_PROXY_STATE, 0);
        pairsprintf(vp, "%u", request->packet->id);
 
        /*
index fe3ed92..9224261 100644 (file)
@@ -625,13 +625,9 @@ static rlm_rcode_t mod_authorize(void *instance, REQUEST *request)
        if (pairfind(request->packet->vps, PW_CHAP_PASSWORD, 0, TAG_ANY) &&
            pairfind(request->packet->vps, PW_CHAP_CHALLENGE, 0, TAG_ANY) == NULL) {
                VALUE_PAIR *vp;
-               uint8_t *p;
 
                vp = radius_paircreate(request, &request->packet->vps, PW_CHAP_CHALLENGE, 0);
-               vp->length = AUTH_VECTOR_LEN;
-               vp->vp_octets = p = talloc_array(vp, uint8_t, vp->length);
-
-               memcpy(p, request->packet->vector, AUTH_VECTOR_LEN);
+               pairmemcpy(vp, request->packet->vector, AUTH_VECTOR_LEN);
        }
 
        if ((r = huntgroup_access(request, inst->huntgroups)) != RLM_MODULE_OK) {