Blame SOURCES/freeradius-access-union-consistently.patch

75e927
From 5e8a69d547461c757abe2870ecbff2aa7a1fea55 Mon Sep 17 00:00:00 2001
75e927
From: Nikolai Kondrashov <Nikolai.Kondrashov@redhat.com>
75e927
Date: Wed, 1 Oct 2014 11:51:51 -0400
75e927
Subject: [PATCH 2/4] Access union value_data members consistently
75e927
75e927
Use the same, appropriate union value_data member for each access of
75e927
BOOLEAN, BYTE and SHORT PW_TYPEs, without assuming they're
75e927
interchangeable with "integer", as that is only true on little-endian
75e927
architectures.
75e927
75e927
This fixes at least this wimax unit test failure on s390x and ppc64:
75e927
75e927
    Mismatch in line 11 of src/tests/unit/wimax.txt, got: 1a 0c 00 00 60 b5 01 06 00 02 03 00 expected: 1a 0c 00 00 60 b5 01 06 00 02 03 01
75e927
---
75e927
 src/lib/print.c                               | 56 ++++++++++++------
75e927
 src/lib/radius.c                              |  8 +--
75e927
 src/lib/valuepair.c                           | 83 +++++++++++++++++++--------
75e927
 src/main/evaluate.c                           |  4 +-
75e927
 src/main/valuepair.c                          |  4 ++
75e927
 src/main/xlat.c                               |  4 +-
75e927
 src/modules/rlm_couchbase/mod.c               | 17 +++++-
75e927
 src/modules/rlm_eap/types/rlm_eap_ttls/ttls.c |  4 +-
75e927
 8 files changed, 128 insertions(+), 52 deletions(-)
75e927
75e927
diff --git a/src/lib/print.c b/src/lib/print.c
75e927
index 67263bc..fc1ae42 100644
75e927
--- a/src/lib/print.c
75e927
+++ b/src/lib/print.c
75e927
@@ -314,6 +314,7 @@ size_t vp_data_prints_value(char *out, size_t outlen,
75e927
 	char const	*a = NULL;
75e927
 	time_t		t;
75e927
 	struct tm	s_tm;
75e927
+	unsigned int	i;
75e927
 
75e927
 	size_t		len = 0, freespace = outlen;
75e927
 
75e927
@@ -365,15 +366,24 @@ size_t vp_data_prints_value(char *out, size_t outlen,
75e927
 		return fr_print_string(data->strvalue, data_len, out, outlen);
75e927
 
75e927
 	case PW_TYPE_INTEGER:
75e927
-	case PW_TYPE_BYTE:
75e927
+		i = data->integer;
75e927
+		goto print_int;
75e927
+
75e927
 	case PW_TYPE_SHORT:
75e927
+		i = data->ushort;
75e927
+		goto print_int;
75e927
+
75e927
+	case PW_TYPE_BYTE:
75e927
+		i = data->byte;
75e927
+
75e927
+print_int:
75e927
 		/* Normal, non-tagged attribute */
75e927
-		if ((v = dict_valbyattr(da->attr, da->vendor, data->integer)) != NULL) {
75e927
+		if ((v = dict_valbyattr(da->attr, da->vendor, i)) != NULL) {
75e927
 			a = v->name;
75e927
 			len = strlen(a);
75e927
 		} else {
75e927
 			/* should never be truncated */
75e927
-			len = snprintf(buf, sizeof(buf), "%u", data->integer);
75e927
+			len = snprintf(buf, sizeof(buf), "%u", i);
75e927
 			a = buf;
75e927
 		}
75e927
 		break;
75e927
@@ -590,12 +600,20 @@ size_t vp_prints_value_json(char *out, size_t outlen, VALUE_PAIR const *vp)
75e927
 	if (!vp->da->flags.has_tag) {
75e927
 		switch (vp->da->type) {
75e927
 		case PW_TYPE_INTEGER:
75e927
-		case PW_TYPE_BYTE:
75e927
-		case PW_TYPE_SHORT:
75e927
 			if (vp->da->flags.has_value) break;
75e927
 
75e927
 			return snprintf(out, freespace, "%u", vp->vp_integer);
75e927
 
75e927
+		case PW_TYPE_SHORT:
75e927
+			if (vp->da->flags.has_value) break;
75e927
+
75e927
+			return snprintf(out, freespace, "%u", (unsigned int) vp->vp_short);
75e927
+
75e927
+		case PW_TYPE_BYTE:
75e927
+			if (vp->da->flags.has_value) break;
75e927
+
75e927
+			return snprintf(out, freespace, "%u", (unsigned int) vp->vp_byte);
75e927
+
75e927
 		case PW_TYPE_SIGNED:
75e927
 			return snprintf(out, freespace, "%d", vp->vp_signed);
75e927
 
75e927
@@ -834,6 +852,8 @@ void vp_printlist(FILE *fp, VALUE_PAIR const *vp)
75e927
 char *vp_aprint_value(TALLOC_CTX *ctx, VALUE_PAIR const *vp, bool escape)
75e927
 {
75e927
 	char *p;
75e927
+	unsigned int i;
75e927
+	DICT_VALUE const *dv;
75e927
 
75e927
 	switch (vp->da->type) {
75e927
 	case PW_TYPE_STRING:
75e927
@@ -860,19 +880,23 @@ char *vp_aprint_value(TALLOC_CTX *ctx, VALUE_PAIR const *vp, bool escape)
75e927
 		break;
75e927
 	}
75e927
 
75e927
-	case PW_TYPE_BYTE:
75e927
-	case PW_TYPE_SHORT:
75e927
 	case PW_TYPE_INTEGER:
75e927
-		{
75e927
-			DICT_VALUE *dv;
75e927
+		i = vp->vp_integer;
75e927
+		goto print_int;
75e927
 
75e927
-			dv = dict_valbyattr(vp->da->attr, vp->da->vendor,
75e927
-					    vp->vp_integer);
75e927
-			if (dv) {
75e927
-				p = talloc_typed_strdup(ctx, dv->name);
75e927
-			} else {
75e927
-				p = talloc_typed_asprintf(ctx, "%u", vp->vp_integer);
75e927
-			}
75e927
+	case PW_TYPE_SHORT:
75e927
+		i = vp->vp_short;
75e927
+		goto print_int;
75e927
+
75e927
+	case PW_TYPE_BYTE:
75e927
+		i = vp->vp_byte;
75e927
+
75e927
+	print_int:
75e927
+		dv = dict_valbyattr(vp->da->attr, vp->da->vendor, i);
75e927
+		if (dv) {
75e927
+			p = talloc_typed_strdup(ctx, dv->name);
75e927
+		} else {
75e927
+			p = talloc_typed_asprintf(ctx, "%u", i);
75e927
 		}
75e927
 		break;
75e927
 
75e927
diff --git a/src/lib/radius.c b/src/lib/radius.c
75e927
index 0a40682..aabc545 100644
75e927
--- a/src/lib/radius.c
75e927
+++ b/src/lib/radius.c
75e927
@@ -3984,18 +3984,18 @@ ssize_t rad_vp2data(uint8_t const **out, VALUE_PAIR const *vp)
75e927
 	}
75e927
 
75e927
 	case PW_TYPE_BOOLEAN:
75e927
-		buffer[0] = vp->vp_integer & 0x01;
75e927
+		buffer[0] = vp->vp_byte & 0x01;
75e927
 		*out = buffer;
75e927
 		break;
75e927
 
75e927
 	case PW_TYPE_BYTE:
75e927
-		buffer[0] = vp->vp_integer & 0xff;
75e927
+		buffer[0] = vp->vp_byte & 0xff;
75e927
 		*out = buffer;
75e927
 		break;
75e927
 
75e927
 	case PW_TYPE_SHORT:
75e927
-		buffer[0] = (vp->vp_integer >> 8) & 0xff;
75e927
-		buffer[1] = vp->vp_integer & 0xff;
75e927
+		buffer[0] = (vp->vp_short >> 8) & 0xff;
75e927
+		buffer[1] = vp->vp_short & 0xff;
75e927
 		*out = buffer;
75e927
 		break;
75e927
 
75e927
diff --git a/src/lib/valuepair.c b/src/lib/valuepair.c
75e927
index 9dcae70..7d6ee88 100644
75e927
--- a/src/lib/valuepair.c
75e927
+++ b/src/lib/valuepair.c
75e927
@@ -1369,65 +1369,100 @@ int pairparsevalue(VALUE_PAIR *vp, char const *value, size_t inlen)
75e927
 	case PW_TYPE_BYTE:
75e927
 	{
75e927
 		char *p;
75e927
-		vp->length = 1;
75e927
+		unsigned int i;
75e927
 
75e927
 		/*
75e927
 		 *	Note that ALL integers are unsigned!
75e927
 		 */
75e927
-		vp->vp_integer = fr_strtoul(value, &p);
75e927
-		if (!*p) {
75e927
-			if (vp->vp_integer > 255) {
75e927
+		i = fr_strtoul(value, &p);
75e927
+
75e927
+		/*
75e927
+		 *	Look for the named value for the given
75e927
+		 *	attribute.
75e927
+		 */
75e927
+		if (*p && !is_whitespace(p)) {
75e927
+			if ((dval = dict_valbyname(vp->da->attr, vp->da->vendor, value)) == NULL) {
75e927
+				fr_strerror_printf("Unknown value '%s' for attribute '%s'", value, vp->da->name);
75e927
+				return -1;
75e927
+			}
75e927
+
75e927
+			vp->vp_byte = dval->value;
75e927
+		} else {
75e927
+			if (i > 255) {
75e927
 				fr_strerror_printf("Byte value \"%s\" is larger than 255", value);
75e927
 				return -1;
75e927
 			}
75e927
-			break;
75e927
+
75e927
+			vp->vp_byte = i;
75e927
 		}
75e927
-		if (is_whitespace(p)) break;
75e927
+
75e927
+		vp->length = 1;
75e927
+		break;
75e927
 	}
75e927
-		goto check_for_value;
75e927
 
75e927
 	case PW_TYPE_SHORT:
75e927
 	{
75e927
 		char *p;
75e927
+		unsigned int i;
75e927
 
75e927
 		/*
75e927
 		 *	Note that ALL integers are unsigned!
75e927
 		 */
75e927
-		vp->vp_integer = fr_strtoul(value, &p);
75e927
-		vp->length = 2;
75e927
-		if (!*p) {
75e927
-			if (vp->vp_integer > 65535) {
75e927
-				fr_strerror_printf("Byte value \"%s\" is larger than 65535", value);
75e927
+		i = fr_strtoul(value, &p);
75e927
+
75e927
+		/*
75e927
+		 *	Look for the named value for the given
75e927
+		 *	attribute.
75e927
+		 */
75e927
+		if (*p && !is_whitespace(p)) {
75e927
+			if ((dval = dict_valbyname(vp->da->attr, vp->da->vendor, value)) == NULL) {
75e927
+				fr_strerror_printf("Unknown value '%s' for attribute '%s'", value, vp->da->name);
75e927
 				return -1;
75e927
 			}
75e927
-			break;
75e927
+
75e927
+			vp->vp_short = dval->value;
75e927
+		} else {
75e927
+			if (i > 65535) {
75e927
+				fr_strerror_printf("Short value \"%s\" is larger than 65535", value);
75e927
+				return -1;
75e927
+			}
75e927
+
75e927
+			vp->vp_short = i;
75e927
 		}
75e927
-		if (is_whitespace(p)) break;
75e927
+
75e927
+		vp->length = 2;
75e927
+		break;
75e927
 	}
75e927
-		goto check_for_value;
75e927
 
75e927
 	case PW_TYPE_INTEGER:
75e927
 	{
75e927
 		char *p;
75e927
+		unsigned int i;
75e927
 
75e927
 		/*
75e927
 		 *	Note that ALL integers are unsigned!
75e927
 		 */
75e927
-		vp->vp_integer = fr_strtoul(value, &p);
75e927
-		vp->length = 4;
75e927
-		if (!*p) break;
75e927
-		if (is_whitespace(p)) break;
75e927
+		i = fr_strtoul(value, &p);
75e927
 
75e927
-	check_for_value:
75e927
 		/*
75e927
 		 *	Look for the named value for the given
75e927
 		 *	attribute.
75e927
 		 */
75e927
-		if ((dval = dict_valbyname(vp->da->attr, vp->da->vendor, value)) == NULL) {
75e927
-			fr_strerror_printf("Unknown value '%s' for attribute '%s'", value, vp->da->name);
75e927
-			return -1;
75e927
+		if (*p && !is_whitespace(p)) {
75e927
+			if ((dval = dict_valbyname(vp->da->attr, vp->da->vendor, value)) == NULL) {
75e927
+				fr_strerror_printf("Unknown value '%s' for attribute '%s'", value, vp->da->name);
75e927
+				return -1;
75e927
+			}
75e927
+
75e927
+			vp->vp_integer = dval->value;
75e927
+		} else {
75e927
+			/*
75e927
+			 *	Value is always within the limits
75e927
+			 */
75e927
+			vp->vp_integer = i;
75e927
 		}
75e927
-		vp->vp_integer = dval->value;
75e927
+
75e927
+		vp->length = 4;
75e927
 	}
75e927
 		break;
75e927
 
75e927
diff --git a/src/main/evaluate.c b/src/main/evaluate.c
75e927
index 5cf597d..a100c70 100644
75e927
--- a/src/main/evaluate.c
75e927
+++ b/src/main/evaluate.c
75e927
@@ -485,11 +485,11 @@ static int do_cast_copy(VALUE_PAIR *dst, VALUE_PAIR const *src)
75e927
 			break;
75e927
 
75e927
 		case PW_TYPE_SHORT:
75e927
-			dst->vp_integer = ntohs(*(uint16_t const *) src->vp_octets);
75e927
+			dst->vp_short = ntohs(*(uint16_t const *) src->vp_octets);
75e927
 			break;
75e927
 
75e927
 		case PW_TYPE_BYTE:
75e927
-			dst->vp_integer = src->vp_octets[0];
75e927
+			dst->vp_byte = src->vp_octets[0];
75e927
 			break;
75e927
 
75e927
 		default:
75e927
diff --git a/src/main/valuepair.c b/src/main/valuepair.c
75e927
index dc2bfc7..2dd517a 100644
75e927
--- a/src/main/valuepair.c
75e927
+++ b/src/main/valuepair.c
75e927
@@ -180,7 +180,11 @@ int radius_compare_vps(UNUSED REQUEST *request, VALUE_PAIR *check, VALUE_PAIR *v
75e927
 			break;
75e927
 
75e927
 		case PW_TYPE_BYTE:
75e927
+			ret = vp->vp_byte - check->vp_byte;
75e927
+			break;
75e927
 		case PW_TYPE_SHORT:
75e927
+			ret = vp->vp_short - check->vp_short;
75e927
+			break;
75e927
 		case PW_TYPE_INTEGER:
75e927
 			ret = vp->vp_integer - check->vp_integer;
75e927
 			break;
75e927
diff --git a/src/main/xlat.c b/src/main/xlat.c
75e927
index f2c8aff..a069919 100644
75e927
--- a/src/main/xlat.c
75e927
+++ b/src/main/xlat.c
75e927
@@ -177,9 +177,11 @@ static ssize_t xlat_integer(UNUSED void *instance, REQUEST *request,
75e927
 
75e927
 	case PW_TYPE_INTEGER:
75e927
 	case PW_TYPE_DATE:
75e927
+		return snprintf(out, outlen, "%u", vp->vp_integer);
75e927
 	case PW_TYPE_BYTE:
75e927
+		return snprintf(out, outlen, "%u", (unsigned int) vp->vp_byte);
75e927
 	case PW_TYPE_SHORT:
75e927
-		return snprintf(out, outlen, "%u", vp->vp_integer);
75e927
+		return snprintf(out, outlen, "%u", (unsigned int) vp->vp_short);
75e927
 
75e927
 	/*
75e927
 	 *	Ethernet is weird... It's network related, so we assume to it should be
75e927
diff --git a/src/modules/rlm_couchbase/mod.c b/src/modules/rlm_couchbase/mod.c
75e927
index cc14677..36406a0 100644
75e927
--- a/src/modules/rlm_couchbase/mod.c
75e927
+++ b/src/modules/rlm_couchbase/mod.c
75e927
@@ -296,22 +296,33 @@ json_object *mod_value_pair_to_json_object(REQUEST *request, VALUE_PAIR *vp)
75e927
 
75e927
 	/* add this attribute/value pair to our json output */
75e927
 	if (!vp->da->flags.has_tag) {
75e927
+		unsigned int i;
75e927
+
75e927
 		switch (vp->da->type) {
75e927
 		case PW_TYPE_INTEGER:
75e927
-		case PW_TYPE_BYTE:
75e927
+			i = vp->vp_integer;
75e927
+			goto print_int;
75e927
+
75e927
 		case PW_TYPE_SHORT:
75e927
+			i = vp->vp_short;
75e927
+			goto print_int;
75e927
+
75e927
+		case PW_TYPE_BYTE:
75e927
+			i = vp->vp_byte;
75e927
+
75e927
+		print_int:
75e927
 			/* skip if we have flags */
75e927
 			if (vp->da->flags.has_value) break;
75e927
 #ifdef HAVE_JSON_OBJECT_NEW_INT64
75e927
 			/* debug */
75e927
 			RDEBUG3("creating new int64 for unsigned 32 bit int/byte/short '%s'", vp->da->name);
75e927
 			/* return as 64 bit int - JSON spec does not support unsigned ints */
75e927
-			return json_object_new_int64(vp->vp_integer);
75e927
+			return json_object_new_int64(i);
75e927
 #else
75e927
 			/* debug */
75e927
 			RDEBUG3("creating new int for unsigned 32 bit int/byte/short '%s'", vp->da->name);
75e927
 			/* return as 64 bit int - JSON spec does not support unsigned ints */
75e927
-			return json_object_new_int(vp->vp_integer);
75e927
+			return json_object_new_int(i);
75e927
 #endif
75e927
 		break;
75e927
 		case PW_TYPE_SIGNED:
75e927
diff --git a/src/modules/rlm_eap/types/rlm_eap_ttls/ttls.c b/src/modules/rlm_eap/types/rlm_eap_ttls/ttls.c
75e927
index 152f4ca..55e8e14 100644
75e927
--- a/src/modules/rlm_eap/types/rlm_eap_ttls/ttls.c
75e927
+++ b/src/modules/rlm_eap/types/rlm_eap_ttls/ttls.c
75e927
@@ -325,12 +325,12 @@ static VALUE_PAIR *diameter2vp(REQUEST *request, REQUEST *fake, SSL *ssl,
75e927
 
75e927
 		case PW_TYPE_BYTE:
75e927
 			if (size != vp->length) goto raw;
75e927
-			vp->vp_integer = data[0];
75e927
+			vp->vp_byte = data[0];
75e927
 			break;
75e927
 
75e927
 		case PW_TYPE_SHORT:
75e927
 			if (size != vp->length) goto raw;
75e927
-			vp->vp_integer = (data[0] * 256) + data[1];
75e927
+			vp->vp_short = (data[0] * 256) + data[1];
75e927
 			break;
75e927
 
75e927
 		case PW_TYPE_SIGNED:
75e927
-- 
75e927
2.1.0
75e927