Repository navigation
Commit af1a2cc
committed
[BUG] Fix misaligned sockaddr_in access in SocketAddr
SocketAddr(u_long, uint16_t) bound a sockaddr_in reference to the sockaddr
storage through a reinterpret_cast. sockaddr is not aligned for a sockaddr_in
on every ABI (alignment 1 on macOS and 2 on Linux versus 4), so the access is
undefined and UBSan reports it:
socket_tools.h:180:29: runtime error: reference binding to misaligned
address 0x00016bda6551 for type 'sockaddr_in', which requires 4 byte
alignment
Store the address in a sockaddr_storage, which is the socket API's type for an
address of any family and is aligned for all of them, and build the IPv4
address in a local sockaddr_in that is copied into the storage, as the string
constructor already does. Replace the sockaddr conversion operators with
addr() and addr_len(): the storage is larger than a sockaddr_in and passing
its full size as the address length to bind() or connect() is rejected on
some platforms, so addr_len() is the length of a sockaddr_in, the only family
stored. getsockname() and accept() keep passing the full storage size, which
is the buffer capacity for those output parameters.
The default constructor sets AF_UNSPEC explicitly, and the tests read the
family through ss_family. New tests cover the integer constructor at an
address only sockaddr_storage alignment can guarantee, the accessors, and a
bind/getsockname/connect/accept round trip on the loopback interface.
Fixes #43071 parent c7b64ec commit af1a2cc
3 files changed
Lines changed: 109 additions & 32 deletions
File tree
- ext
- include/opentelemetry/ext/http/server
- test/http
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
18 | 22 | | |
19 | 23 | | |
20 | 24 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
167 | 167 | | |
168 | 168 | | |
169 | 169 | | |
170 | | - | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
171 | 175 | | |
172 | 176 | | |
173 | 177 | | |
174 | 178 | | |
175 | 179 | | |
176 | | - | |
| 180 | + | |
177 | 181 | | |
178 | 182 | | |
179 | 183 | | |
180 | | - | |
| 184 | + | |
181 | 185 | | |
182 | 186 | | |
183 | 187 | | |
| 188 | + | |
184 | 189 | | |
185 | 190 | | |
186 | 191 | | |
| |||
264 | 269 | | |
265 | 270 | | |
266 | 271 | | |
267 | | - | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
268 | 276 | | |
269 | | - | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
270 | 280 | | |
271 | 281 | | |
272 | 282 | | |
273 | | - | |
| 283 | + | |
274 | 284 | | |
275 | 285 | | |
276 | 286 | | |
| |||
289 | 299 | | |
290 | 300 | | |
291 | 301 | | |
292 | | - | |
| 302 | + | |
293 | 303 | | |
294 | 304 | | |
295 | 305 | | |
| |||
302 | 312 | | |
303 | 313 | | |
304 | 314 | | |
305 | | - | |
| 315 | + | |
306 | 316 | | |
307 | 317 | | |
308 | 318 | | |
309 | 319 | | |
310 | 320 | | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
322 | 331 | | |
323 | 332 | | |
324 | 333 | | |
| |||
388 | 397 | | |
389 | 398 | | |
390 | 399 | | |
391 | | - | |
| 400 | + | |
392 | 401 | | |
393 | 402 | | |
394 | 403 | | |
| |||
418 | 427 | | |
419 | 428 | | |
420 | 429 | | |
421 | | - | |
| 430 | + | |
422 | 431 | | |
423 | 432 | | |
424 | 433 | | |
425 | 434 | | |
426 | 435 | | |
427 | 436 | | |
428 | | - | |
| 437 | + | |
429 | 438 | | |
430 | | - | |
| 439 | + | |
431 | 440 | | |
432 | | - | |
| 441 | + | |
433 | 442 | | |
434 | 443 | | |
435 | 444 | | |
| |||
442 | 451 | | |
443 | 452 | | |
444 | 453 | | |
445 | | - | |
| 454 | + | |
446 | 455 | | |
447 | | - | |
| 456 | + | |
448 | 457 | | |
449 | | - | |
| 458 | + | |
450 | 459 | | |
451 | 460 | | |
452 | 461 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
5 | 7 | | |
6 | 8 | | |
7 | | - | |
| 9 | + | |
| 10 | + | |
8 | 11 | | |
9 | 12 | | |
10 | 13 | | |
| |||
17 | 20 | | |
18 | 21 | | |
19 | 22 | | |
20 | | - | |
| 23 | + | |
21 | 24 | | |
22 | 25 | | |
23 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
24 | 88 | | |
25 | 89 | | |
26 | 90 | | |
27 | | - | |
| 91 | + | |
28 | 92 | | |
29 | 93 | | |
30 | 94 | | |
| |||
57 | 121 | | |
58 | 122 | | |
59 | 123 | | |
60 | | - | |
| 124 | + | |
61 | 125 | | |
62 | 126 | | |
63 | 127 | | |
| |||
67 | 131 | | |
68 | 132 | | |
69 | 133 | | |
70 | | - | |
| 134 | + | |
71 | 135 | | |
72 | 136 | | |
73 | 137 | | |
| |||
0 commit comments