From: Arran Cudbard-Bell Date: Thu, 3 Feb 2022 10:38:41 +0000 (-0500) Subject: Fix parsing some mac addresses X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=26d56d91ed20c48927d15589804308126fd5bf8d;p=thirdparty%2Ffreeradius-server.git Fix parsing some mac addresses --- diff --git a/src/lib/util/value.c b/src/lib/util/value.c index e348ed180ae..161a77adba2 100644 --- a/src/lib/util/value.c +++ b/src/lib/util/value.c @@ -4764,8 +4764,14 @@ parse: * The string gets converted to a network-order * 8-byte number, and then the lower bytes of * that get copied to the ethernet address. + * + * Note: We need to check for a terminal sequence + * after the number, else we may just end up + * parsing the first hexit and returning. + * + * i.e. 1c:00:00:00:00 -> 1 */ - if ((fr_sbuff_out(NULL, &num, &our_in) > 0) && !fr_sbuff_is_char(&our_in, ':')) { + if ((fr_sbuff_out(NULL, &num, &our_in) > 0) && fr_sbuff_is_terminal(&our_in, rules->terminals)) { num = htonll(num); fr_dbuff_in_memcpy(&dbuff, ((uint8_t *) &num) + 2, sizeof(dst->vb_ether)); @@ -4954,7 +4960,8 @@ ssize_t fr_value_box_from_str(TALLOC_CTX *ctx, fr_value_box_t *dst, if (slen <= 0) return slen; if (slen != (ssize_t)inlen) { - fr_strerror_printf("%zu bytes of trailing data after string value \"%pV\"", + fr_strerror_printf("Failed parsing '%s'. %zu bytes of trailing data after string value \"%pV\"", + fr_type_to_str(dst_type), inlen - slen, fr_box_strvalue_len(in + slen, inlen - slen)); return (slen - inlen) - 1; diff --git a/src/tests/modules/json/regression01.unlang b/src/tests/modules/json/regression01.unlang new file mode 100644 index 00000000000..6a6554b53e3 --- /dev/null +++ b/src/tests/modules/json/regression01.unlang @@ -0,0 +1,16 @@ + +# In the original failure parsing the mac-address results in a "trailing garbage" error +map json '{"externalId":"10000000001","osFamily":"IOS","macAddress":"6C:4D:73:8B:51:00","guid":"Enrollment-000000000-0000-0000-0000-000000000000","isRevoked":false,"configurationType":"HS2R1","certificateSerialNumber":"0000c92c8d4896458ecfb70323d5cf81ddc0000","isExpired":false}' { + &Tmp-String-0 := '$.externalId' + &Tmp-Ethernet-0 := '$.macAddress' +} + +if (&Tmp-String-0 != "10000000001") { + test_fail +} + +if (&Tmp-Ethernet-0 != 6C:4D:73:8B:51:00) { + test_fail +} + +test_pass