]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Fix parsing some mac addresses
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 3 Feb 2022 10:38:41 +0000 (05:38 -0500)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Thu, 3 Feb 2022 10:38:41 +0000 (05:38 -0500)
src/lib/util/value.c
src/tests/modules/json/regression01.unlang [new file with mode: 0644]

index e348ed180aee49910c4e5369d46e61e21c1f4ec3..161a77adba2a32dcdda5f89d9a95ae3d6fee1973 100644 (file)
@@ -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 (file)
index 0000000..6a6554b
--- /dev/null
@@ -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