]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Rewrite check on length in dhcpv6_print_hex()
authorJames Jones <jejones3141@gmail.com>
Fri, 2 Jun 2023 18:44:47 +0000 (13:44 -0500)
committerAlan DeKok <aland@freeradius.org>
Wed, 7 Jun 2023 07:15:44 +0000 (03:15 -0400)
We suspect that coverity is confused by the check as written, and
so rewrite it so that the variable checked is alone on the LHS of
the comparison.

src/protocols/dhcpv6/base.c

index bdc486f501779552f3cb87f64bfa02890c649ae1..a079ec2290cecca28a5ef47771e68ac209ab7341 100644 (file)
@@ -881,12 +881,11 @@ static void dhcpv6_print_hex(FILE *fp, uint8_t const *packet, size_t packet_len,
                fprintf(fp, "%.*s", depth + 1, tabs);
                fprintf(fp, "%04x %04x\t", fr_nbo_to_uint16(option), length);
 
-               if ((option + 4 + length) > end) {
+               if (length > end - (option + 4)) {
                        print_hex_data(fp, option + 4, end - (option + 4), depth + 3);
                        break;
                }
 
-               /* coverity[tainted_data] */
                print_hex_data(fp, option + 4, length, depth + 3);
                if ((option[0] == 0) && (option[1] == attr_relay_message->attr)) {
                        dhcpv6_print_hex(fp, option + 4, length, depth + 2);