Fix CUI processing
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 15 May 2014 20:55:25 +0000 (21:55 +0100)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 15 May 2014 20:56:04 +0000 (21:56 +0100)
src/lib/radius.c
src/lib/valuepair.c
src/tests/unit/rfc.txt

index 002f737..2df5717 100644 (file)
@@ -3444,11 +3444,11 @@ ssize_t data2vp(RADIUS_PACKET *packet,
                 *      will break assumptions about CUI.  We know
                 *      this, but Coverity doesn't.
                 */
-               if (da->type != PW_TYPE_STRING) return -1;
+               if (da->type != PW_TYPE_OCTETS) return -1;
 #endif
 
-               data = (uint8_t const *) "";
-               datalen = 1;
+               data = NULL;
+               datalen = 0;
                goto alloc_cui; /* skip everything */
        }
 
index 7786f45..127e6bd 100644 (file)
@@ -2883,24 +2883,27 @@ static void pairtypeset(VALUE_PAIR *vp)
  *
  * @param[in,out] vp to update
  * @param[in] src data to copy
- * @param[in] size of the data
+ * @param[in] size of the data, may be 0 in which case previous value will be freed.
  */
 void pairmemcpy(VALUE_PAIR *vp, uint8_t const *src, size_t size)
 {
-       uint8_t *p, *q;
+       uint8_t *p = NULL, *q;
 
        VERIFY_VP(vp);
 
-       p = talloc_memdup(vp, src, size);
-       if (!p) return;
-       talloc_set_type(p, uint8_t);
+       if (size > 0) {
+               p = talloc_memdup(vp, src, size);
+               if (!p) return;
+               talloc_set_type(p, uint8_t);
+       }
 
        memcpy(&q, &vp->vp_octets, sizeof(q));
-       talloc_free(q);
+       TALLOC_FREE(q);
 
        vp->vp_octets = p;
        vp->length = size;
-       pairtypeset(vp);
+
+       if (size > 0) pairtypeset(vp);
 }
 
 /** Reparent an allocated octet buffer to a VALUE_PAIR
index 4cc203d..92c7d49 100644 (file)
@@ -99,7 +99,7 @@ data
 
 # except for CUI.  Thank you, WiMAX!
 decode 59 02
-data Chargeable-User-Identity = ''
+data Chargeable-User-Identity = 0x
 
 # Hah! Thought you had it figured out, didn't you?
 encode -