Commit ba55373
addr: fix
Currently, the `Addr::to_http_authority` method panics when called on a
`SocketAddr` which is an IPv6 address with port 80. This method does not
panic when called with IPv4 addresses, or with IPv6 addresses whose
ports are *not* port 80. This was initially caught by oss-fuzz; see
[here][1] for details.
The panic occurs because when an IPv6+ address occurs in an authority,
it must be within square brackets, as per [RFC3986, Section 3.2][2]. The
square brackets distinguish between colons in the IPv6 address and the
colon separating the address and port. When the `SocketAddr`'s port is
not port 80, we format it including the port, and the `fmt::Display`
output from IPv6 `SocketAddr`s includes the square brackets as expected.
However, when the socket's port *is* port 80, we have special logic for
eliding the port from the authority. This works fine for IPv4, where we
can just call `addr.ip().to_string()` to nicely format the address.
However, with IPv6 addresses, this only formats the address itself,
*not* the square brackets. According to RFC3986, square brackets are
mandatory for *all* IPv6 addresses, even when port 80 is elided.
This branch fixes the panic by changing `Addr::to_http_authority` to
include square brackets when formatting IPv6 `SocketAddr`s with port 80.
I've also improved on @olix0r's original test cases from
dbf898a to include IPv6 addrs with and without
shorthand, and to test ports that are and are not port 80. These tests
helped catch the panic, and may be useful to guard against future
regressions.
Fixes linkerd/linkerd2#6020
[1]: https://oss-fuzz.com/testcase-detail/6502844766224384
[2]: https://tools.ietf.org/html/rfc3986#section-3.2
Signed-off-by: Eliza Weisman <[email protected]>
Co-authored-by: Oliver Gould <[email protected]>to_http_authority panic with IPv6 (#976)1 parent 372a804 commit ba55373
1 file changed
+78
-4
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | | - | |
86 | | - | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
87 | 104 | | |
88 | | - | |
89 | | - | |
90 | 105 | | |
91 | 106 | | |
92 | 107 | | |
| |||
257 | 272 | | |
258 | 273 | | |
259 | 274 | | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
260 | 334 | | |
261 | 335 | | |
262 | 336 | | |
| |||
0 commit comments