]> The Tcpdump Group git mirrors - libpcap/commitdiff
Require "byte" argument value to be within range.
authorDenis Ovsienko <[email protected]>
Thu, 27 Mar 2025 18:17:31 +0000 (18:17 +0000)
committerDenis Ovsienko <[email protected]>
Thu, 27 Mar 2025 20:38:13 +0000 (20:38 +0000)
CHANGES
gencode.c
testprogs/TESTrun

diff --git a/CHANGES b/CHANGES
index ecf7f49a28e20b6183cfc75c0d77cec59ca872ae..b58cd7a036f765e031416abecf4da133acc06fe5 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -57,6 +57,7 @@ DayOfTheWeek, Month DD, YYYY / The Tcpdump Group
       Use the correct IS-IS PDU type offset for DLT_C_HDLC.
       Use the correct bit mask for IS-IS PDU type value.
       Fix the "|" and "&" operators of the "byte" primitive.
+      Require "byte" argument value to be within range.
     rpcap:
       Support user names and passwords in rpcap:// and rpcaps:// URLs.
       Add a -t flag to rpcapd to specify the data channel port; from
index 40614b93dc34f6c886e546855ebba94a9977dda5..cc11f90ba6263bd139660003e6087ede12b49b44 100644 (file)
--- a/gencode.c
+++ b/gencode.c
@@ -8123,6 +8123,8 @@ gen_byteop(compiler_state_t *cstate, int op, int idx, bpf_u_int32 val)
        if (setjmp(cstate->top_ctx))
                return (NULL);
 
+       assert_maxval(cstate, "byte argument", val, UINT8_MAX);
+
        switch (op) {
        default:
                abort();
index 5ca0d7a37823df8d5e84f5c1f5b6d776c3124646..c0fb5ab10662f10d12f128fc258d91481300db01 100755 (executable)
@@ -12223,6 +12223,36 @@ my @reject_tests = (
                expr => 'byte 1 >> 2',
                errstr => 'syntax error',
        },
+       {
+               name => 'byte_eq_256',
+               DLT => 'IPV4',
+               expr => 'byte 1 = 256',
+               errstr => 'byte argument 256 greater than maximum 255',
+       },
+       {
+               name => 'byte_lt_256',
+               DLT => 'IPV4',
+               expr => 'byte 1 < 256',
+               errstr => 'byte argument 256 greater than maximum 255',
+       },
+       {
+               name => 'byte_gt_256',
+               DLT => 'IPV4',
+               expr => 'byte 1 > 256',
+               errstr => 'byte argument 256 greater than maximum 255',
+       },
+       {
+               name => 'byte_and_256',
+               DLT => 'IPV4',
+               expr => 'byte 1 & 256',
+               errstr => 'byte argument 256 greater than maximum 255',
+       },
+       {
+               name => 'byte_or_256',
+               DLT => 'IPV4',
+               expr => 'byte 1 | 256',
+               errstr => 'byte argument 256 greater than maximum 255',
+       },
 );
 
 push @reject_tests, {