|
1 | 1 | /* |
2 | | - * Authored by Alex Hultman, 2018-2020. |
| 2 | + * Authored by Alex Hultman, 2018-2026. |
3 | 3 | * Intellectual property of third-party. |
4 | 4 |
|
5 | 5 | * Licensed under the Apache License, Version 2.0 (the "License"); |
@@ -69,6 +69,10 @@ T _cond_byte_swap(T value) { |
69 | 69 | struct ProxyParser { |
70 | 70 | private: |
71 | 71 | 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; |
72 | 76 |
|
73 | 77 | /* Default family of 0 signals no proxy address */ |
74 | 78 | uint8_t family = 0; |
@@ -161,11 +165,15 @@ struct ProxyParser { |
161 | 165 | //printf("Family: %d\n", (header.fam & 0xf0) >> 4); |
162 | 166 | //printf("Transport: %d\n", (header.fam & 0x0f)); |
163 | 167 |
|
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; |
166 | 172 |
|
167 | | - /* Copy payload */ |
168 | | - memcpy(&addr, data.data() + 16, hostLength); |
| 173 | + memcpy(&addr, data.data() + 16, hostLength); |
| 174 | + |
| 175 | + done = true; |
| 176 | + } |
169 | 177 |
|
170 | 178 | /* We consumed everything */ |
171 | 179 | return {true, 16 + hostLength}; |
|
0 commit comments