The BPF filter insert logic had shadowed declaration of len.

Signed-off-by: Stephen Hemminger <step...@networkplumber.org>
---
 lib/pcapng/rte_pcapng.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/lib/pcapng/rte_pcapng.c b/lib/pcapng/rte_pcapng.c
index 2a07b4c1f5..a46f4bf0bf 100644
--- a/lib/pcapng/rte_pcapng.c
+++ b/lib/pcapng/rte_pcapng.c
@@ -296,16 +296,15 @@ rte_pcapng_add_interface(rte_pcapng_t *self, uint16_t 
port,
                opt = pcapng_add_option(opt, PCAPNG_IFB_HARDWARE,
                                         ifhw, strlen(ifhw));
        if (filter) {
-               size_t len;
+               size_t filter_len = strlen(filter) + 1;
 
-               len = strlen(filter) + 1;
                opt->code = PCAPNG_IFB_FILTER;
-               opt->length = len;
+               opt->length = filter_len;
                /* Encoding is that the first octet indicates string vs BPF */
                opt->data[0] = 0;
-               memcpy(opt->data + 1, filter, strlen(filter));
+               memcpy(opt->data + 1, filter, filter_len - 1);
 
-               opt = (struct pcapng_option *)((uint8_t *)opt + 
pcapng_optlen(len));
+               opt = (struct pcapng_option *)((uint8_t *)opt + 
pcapng_optlen(filter_len));
        }
 
        opt = pcapng_add_option(opt, PCAPNG_OPT_END, NULL, 0);
-- 
2.47.2

Reply via email to