Skip to content
Open
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
6 changes: 6 additions & 0 deletions cmd/core/display_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,12 @@ func displayFar(sb *strings.Builder, far *ie.IE) {
}

func displayPdr(sb *strings.Builder, pdr *ie.IE) {
defer func() {
if r := recover(); r != nil {
log.Warn().Msgf("recovered from panic while formatting PDR for logging: %v", r)
}
}()

pdrId, _ := pdr.PDRID()
fmt.Fprintf(sb, "PDR ID: %d \n", pdrId)

Expand Down
27 changes: 27 additions & 0 deletions cmd/core/display_utils_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package core

import (
"strings"
"testing"

"github.com/wmnsk/go-pfcp/ie"
)

// TestDisplayPdrMalformedSdfFilter pins displayPdr against a PDI whose SDF
// Filter claims a Flow-Description length far longer than the bytes actually
// present. go-pfcp's SDFFilterFields.UnmarshalBinary slices past the buffer
// in that case and panics; displayPdr is a logging path and must not take
// the UPF down with it.
func TestDisplayPdrMalformedSdfFilter(t *testing.T) {
// Flags=0x01 (FD present), spare octet, FDLength=0xFFFE, one byte of
// actual description.
malformedSdfFilter := ie.New(ie.SDFFilter, []byte{0x01, 0x00, 0xFF, 0xFE, 0x41})
pdi := ie.NewPDI(
ie.NewSourceInterface(ie.SrcInterfaceAccess),
malformedSdfFilter,
)
pdr := ie.NewCreatePDR(ie.NewPDRID(1), pdi)

var sb strings.Builder
displayPdr(&sb, pdr)
}