Skip to content

Commit 67ae3cc

Browse files
authored
Don't allow partial host buffers (#947)
1 parent d534b60 commit 67ae3cc

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

internal/test/integration/docker-compose-python-aws.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,7 @@ services:
88
- "4566:4566"
99

1010
testserver:
11-
build:
12-
context: ../../../internal/test/integration/components/pythonawsclient/
13-
dockerfile: Dockerfile
14-
image: hatest-testserver-python-aws-client
11+
image: ghcr.io/open-telemetry/obi-testimg:python_aws_s3-0.0.1
1512
ports:
1613
- "${TEST_SERVICE_PORTS}"
1714
depends_on:

pkg/ebpf/common/http_transform.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,10 @@ func httpHostFromBuf(req []byte) (string, int) {
293293

294294
rIdx := strings.Index(buf, "\r")
295295

296+
// only parse full host information, partial may
297+
// get the wrong name or wrong port
296298
if rIdx < 0 {
297-
rIdx = len(buf)
299+
return "", -1
298300
}
299301

300302
host, portStr, err := net.SplitHostPort(buf[:rIdx])

pkg/ebpf/common/http_transform_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,18 +201,25 @@ func TestToRequestTrace_BadHost(t *testing.T) {
201201
End: 789012,
202202
HostPort: 0,
203203
Service: svc.Attrs{},
204-
Statement: "http;example.c",
204+
Statement: "http;",
205205
}
206206
assert.Equal(t, expected, result)
207207

208208
s, p := httpHostFromBuf(record.Buf[:])
209-
assert.Equal(t, "example.c", s)
209+
assert.Empty(t, s)
210210
assert.Equal(t, -1, p)
211211

212212
var record1 BPFHTTPInfo
213213
copy(record1.Buf[:], "GET /hello HTTP/1.1\r\nHost: example.c:23")
214214

215215
s, p = httpHostFromBuf(record1.Buf[:])
216+
assert.Empty(t, s)
217+
assert.Equal(t, -1, p)
218+
219+
var record4 BPFHTTPInfo
220+
copy(record4.Buf[:], "GET /hello HTTP/1.1\r\nHost: example.c:23\r")
221+
222+
s, p = httpHostFromBuf(record4.Buf[:])
216223
assert.Equal(t, "example.c", s)
217224
assert.Equal(t, 23, p)
218225

0 commit comments

Comments
 (0)