Skip to content

Commit

Permalink
packetbeat/route: fix test failure on Windows 2022 (#39822)
Browse files Browse the repository at this point in the history
Windows 2022 appears to have added new text to the output of netsh. The text
is interpreted as having three fields. This impact on the behaviour of the
field splitting which expects five.

- Originally this would cause a panic due to bounds checking. This was fixed
  in #39757 by erroring on an unexpectedly short line.
- The fieldsN helper expects lines to be n fields or longer, but does not
  terminate on lines with fewer fields.

So treat the first blank line found in the table as the end of the table and
fix the fieldsN helper.
  • Loading branch information
efd6 authored Jun 7, 2024
1 parent 132a06b commit 35f8d09
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG-developer.next.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ The list below covers the major changes between 7.0.0-rc2 and main only.
- Fix copy arguments for strict aligned architectures. {pull}36976[36976]
- Fix panic when more than 32767 pipeline clients are active. {issue}38197[38197] {pull}38556[38556]
- Skip flakey metrics test on windows in filebeat httpjson input. {issue}39676[39676] {pull}39678[39678]
- Fix flakey test on Windows 2022 in packetbeat/route. {issue}39698[39698] {pull}39822[39822]

==== Added

Expand Down
1 change: 0 additions & 1 deletion packetbeat/route/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ import (
)

func TestDefault(t *testing.T) {
t.Skip("Flaky test: https://github.com/elastic/beats/issues/39698")
for _, family := range []int{syscall.AF_INET, syscall.AF_INET6} {
wantIface, wantIndex, wantErr := defaultRoute(family)
if wantErr != nil && wantErr != ErrNotFound {
Expand Down
9 changes: 8 additions & 1 deletion packetbeat/route/route_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ func defaultRoute(af int) (name string, index int, err error) {
for inTable := false; sc.Scan(); {
f := strings.Fields(sc.Text())
if len(f) == 0 {
if inTable {
break
}
continue
}
if !inTable {
Expand Down Expand Up @@ -94,6 +97,9 @@ func defaultRoute(af int) (name string, index int, err error) {
for inTable := false; sc.Scan(); {
f := fieldsN(sc.Text(), 5)
if len(f) == 0 {
if inTable {
break
}
continue
}
if !inTable {
Expand Down Expand Up @@ -152,6 +158,7 @@ func fieldsN(s string, n int) []string {
}
var f []string
for s != "" {
l := len(s)
for i, r := range s {
if unicode.IsSpace(r) {
f = append(f, s[:i])
Expand All @@ -165,7 +172,7 @@ func fieldsN(s string, n int) []string {
break
}
}
if len(f) == n-1 {
if len(f) == n-1 || len(s) == l {
break
}
}
Expand Down

0 comments on commit 35f8d09

Please sign in to comment.