diff --git a/pkg/dynamicinstrumentation/eventparser/event_parser.go b/pkg/dynamicinstrumentation/eventparser/event_parser.go index a40d8056c6cc4..2d6d81e28c994 100644 --- a/pkg/dynamicinstrumentation/eventparser/event_parser.go +++ b/pkg/dynamicinstrumentation/eventparser/event_parser.go @@ -92,19 +92,20 @@ func parseParamValue(definition *ditypes.Param, buffer []byte) (*ditypes.Param, } valueStack := newParamStack() - for bufferIndex+8 < len(buffer) { + for bufferIndex <= len(buffer) { paramDefinition := definitionStack.pop() if paramDefinition == nil { break } if reflect.Kind(paramDefinition.Kind) == reflect.String { - if len(buffer) > bufferIndex+int(paramDefinition.Size) { - paramDefinition.ValueStr = string(buffer[bufferIndex : bufferIndex+int(paramDefinition.Size)]) - bufferIndex += int(paramDefinition.Size) + if bufferIndex+int(paramDefinition.Size) > len(buffer) { + break } + paramDefinition.ValueStr = string(buffer[bufferIndex : bufferIndex+int(paramDefinition.Size)]) + bufferIndex += int(paramDefinition.Size) valueStack.push(paramDefinition) } else if !isTypeWithHeader(paramDefinition.Kind) { - if bufferIndex+int(paramDefinition.Size) >= len(buffer) { + if bufferIndex+int(paramDefinition.Size) > len(buffer) { break } // This is a regular value (no sub-fields). @@ -113,7 +114,7 @@ func parseParamValue(definition *ditypes.Param, buffer []byte) (*ditypes.Param, bufferIndex += int(paramDefinition.Size) valueStack.push(paramDefinition) } else if reflect.Kind(paramDefinition.Kind) == reflect.Pointer { - if bufferIndex+int(paramDefinition.Size) >= len(buffer) { + if bufferIndex+int(paramDefinition.Size) > len(buffer) { break } paramDefinition.Fields = append(paramDefinition.Fields, valueStack.pop()) diff --git a/pkg/dynamicinstrumentation/eventparser/event_parser_test.go b/pkg/dynamicinstrumentation/eventparser/event_parser_test.go index 0ee91b97d0614..e169eabad44ed 100644 --- a/pkg/dynamicinstrumentation/eventparser/event_parser_test.go +++ b/pkg/dynamicinstrumentation/eventparser/event_parser_test.go @@ -111,6 +111,28 @@ func TestParseParamValue(t *testing.T) { }, }, }, + { + name: "same sized string", + inputBuffer: []byte{ + 65, 65, 65, + }, + inputDefinition: &ditypes.Param{ + Type: "string", Size: 0x3, Kind: 0x18, + }, + expectedValue: &ditypes.Param{ + ValueStr: "AAA", Type: "string", Size: 0x3, Kind: 0x18, + }, + }, + { + name: "empty string", + inputBuffer: []byte{}, + inputDefinition: &ditypes.Param{ + Type: "string", Size: 0x0, Kind: 0x18, + }, + expectedValue: &ditypes.Param{ + ValueStr: "", Type: "string", Size: 0x0, Kind: 0x18, + }, + }, } for _, tt := range tests {