Skip to content

Commit 7fd2be6

Browse files
committed
Fix ProxyParser for L4 proxies by only reading data once
1 parent 8b08a07 commit 7fd2be6

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

src/ProxyParser.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Authored by Alex Hultman, 2018-2020.
2+
* Authored by Alex Hultman, 2018-2026.
33
* Intellectual property of third-party.
44
55
* Licensed under the Apache License, Version 2.0 (the "License");
@@ -69,6 +69,10 @@ T _cond_byte_swap(T value) {
6969
struct ProxyParser {
7070
private:
7171
union proxy_addr addr = {};
72+
/* We must always consume all PROXY v2 data, even if done, but we may not overwrite our
73+
* parsed-out data one read for the first time. This property mainly fixes L4 TCP-only
74+
* proxying where no HTTP-level cleaning is applied. */
75+
bool done = false;
7276

7377
/* Default family of 0 signals no proxy address */
7478
uint8_t family = 0;
@@ -161,11 +165,15 @@ struct ProxyParser {
161165
//printf("Family: %d\n", (header.fam & 0xf0) >> 4);
162166
//printf("Transport: %d\n", (header.fam & 0x0f));
163167

164-
/* We have 0 family by default, and UNSPEC is 0 as well */
165-
family = header.fam;
168+
/* Copy payload (only if not already done so before) */
169+
if (!done) {
170+
/* We have 0 family by default, and UNSPEC is 0 as well */
171+
family = header.fam;
166172

167-
/* Copy payload */
168-
memcpy(&addr, data.data() + 16, hostLength);
173+
memcpy(&addr, data.data() + 16, hostLength);
174+
175+
done = true;
176+
}
169177

170178
/* We consumed everything */
171179
return {true, 16 + hostLength};

0 commit comments

Comments
 (0)