Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug #792 avoid assertion and other fixes #873

Merged
merged 1 commit into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@
- configure.ac: unify search dirs for pcap and add lib32 (#819)
- CVE-2023-4256 double free in tcprewrite DLT_JUNIPER_ETHER (#813 #851)
- dlt_jnpr_ether_cleanup: check config before cleanup (#812 #851)
- nanosecond timestamps (#796)
- SEGV on invalid Juniper Ethernet header length (#811)
- nanosecond timestamps support (#796)
- Linux cooked packet fatal error (#792)
- low PPS values run at full speed after several days (#779)
- create DLT_LINUX_SLL2 plugin (#727)

Expand Down
14 changes: 9 additions & 5 deletions src/tcpedit/plugins/dlt_en10mb/en10mb.c
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,7 @@
* Returns: TCPEDIT_ERROR | TCPEDIT_OK | TCPEDIT_WARN
*/
int
dlt_en10mb_encode(tcpeditdlt_t *ctx, u_char *packet, int pktlen, tcpr_dir_t dir)

Check warning on line 467 in src/tcpedit/plugins/dlt_en10mb/en10mb.c

View workflow job for this annotation

GitHub Actions / cpp-linter

src/tcpedit/plugins/dlt_en10mb/en10mb.c:467:1 [readability-function-cognitive-complexity]

function 'dlt_en10mb_encode' has cognitive complexity of 82 (threshold 25)
{
struct tcpr_802_1q_hdr *vlan_hdr;
struct tcpr_ethernet_hdr *eth;
Expand Down Expand Up @@ -519,9 +519,9 @@
}

/* newl2len for some other DLT -> ethernet */
else if (config->vlan == TCPEDIT_VLAN_ADD) {
/* if add a vlan then 18, */
newl2len = TCPR_802_1Q_H;
else {
newl2len = config->vlan == TCPEDIT_VLAN_ADD ? TCPR_802_1Q_H : TCPR_802_3_H;
oldl2len = ctx->l2len;
}

if ((uint32_t)pktlen < newl2len || pktlen + newl2len - ctx->l2len > MAXPACKET) {
Expand Down Expand Up @@ -555,7 +555,6 @@

/* update the total packet length */
pktlen += (int)(newl2len - oldl2len);
ctx->l2len += (int)(newl2len - oldl2len);

/* set the src & dst address as the first 12 bytes */
eth = (struct tcpr_ethernet_hdr *)(packet + ctx->l2offset);
Expand Down Expand Up @@ -665,6 +664,11 @@
}
}

if (newl2len == TCPR_802_3_H) {
/* all we need for 802.3 is the proto */
eth->ether_type = ctx->proto;
}

if (config->vlan == TCPEDIT_VLAN_ADD || (config->vlan == TCPEDIT_VLAN_OFF && extra->vlan)) {
vlan_hdr = (struct tcpr_802_1q_hdr *)(packet + extra->vlan_offset);
if (config->vlan == TCPEDIT_VLAN_ADD) {
Expand Down Expand Up @@ -812,7 +816,7 @@
if (l2len == -1 || pktlen < l2len)
return NULL;

assert(ctx->decoded_extra_size == sizeof(*extra));
assert(ctx->decoded_extra_size >= sizeof(*extra));
extra = (en10mb_extra_t *)ctx->decoded_extra;
eth = (struct tcpr_ethernet_hdr *)(packet + ctx->l2offset);
assert(eth);
Expand Down
Loading