Commit 5800834
[chore] Make mapstructure hooks safe against untyped nils (open-telemetry#13001)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### Description
If we enable `DecodeNil` as true, we may have [untyped
nils](https://go.dev/doc/faq#nil_error) being passed. Unfortunately,
these are not valid values for `reflect`, which leads to surprising
behavior such as golang/go/issues/51649.
Unfortunately, the default hooks from mapstructure do not deal with this
properly. To account for this, we:
- Vendor and change the `ComposeDecodeHookFunc` function so that this
case is accounted for the kinds of hooks that just won't work with
untyped nils
- Create a safe wrapper for the hooks that do work with untyped nils.
This wrapper is used in all hooks, but in the interest of keeping as
close to what I would imagine upstream will accept, I did not add this
to the compose function.
This should not have any end-user observable behavior.
<!-- Issue number if applicable -->
#### Link to tracking issue
Attempt to work around
open-telemetry#12996 (comment)
---------
Co-authored-by: Evan Bradley <[email protected]>1 parent 6bd77b3 commit 5800834
File tree
2 files changed
+132
-11
lines changed- confmap
- internal/third_party/composehook
2 files changed
+132
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
| |||
234 | 235 | | |
235 | 236 | | |
236 | 237 | | |
237 | | - | |
| 238 | + | |
238 | 239 | | |
239 | 240 | | |
240 | 241 | | |
| |||
306 | 307 | | |
307 | 308 | | |
308 | 309 | | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
309 | 327 | | |
310 | 328 | | |
311 | 329 | | |
| |||
355 | 373 | | |
356 | 374 | | |
357 | 375 | | |
358 | | - | |
| 376 | + | |
359 | 377 | | |
360 | 378 | | |
361 | 379 | | |
| |||
375 | 393 | | |
376 | 394 | | |
377 | 395 | | |
378 | | - | |
| 396 | + | |
379 | 397 | | |
380 | 398 | | |
381 | 399 | | |
| |||
422 | 440 | | |
423 | 441 | | |
424 | 442 | | |
425 | | - | |
| 443 | + | |
426 | 444 | | |
427 | 445 | | |
428 | 446 | | |
| |||
455 | 473 | | |
456 | 474 | | |
457 | 475 | | |
458 | | - | |
| 476 | + | |
459 | 477 | | |
460 | 478 | | |
461 | 479 | | |
462 | 480 | | |
463 | 481 | | |
464 | 482 | | |
465 | | - | |
| 483 | + | |
466 | 484 | | |
467 | 485 | | |
468 | 486 | | |
| |||
495 | 513 | | |
496 | 514 | | |
497 | 515 | | |
498 | | - | |
| 516 | + | |
499 | 517 | | |
500 | 518 | | |
501 | 519 | | |
502 | 520 | | |
503 | 521 | | |
504 | 522 | | |
505 | | - | |
| 523 | + | |
506 | 524 | | |
507 | 525 | | |
508 | 526 | | |
| |||
520 | 538 | | |
521 | 539 | | |
522 | 540 | | |
523 | | - | |
| 541 | + | |
524 | 542 | | |
525 | 543 | | |
526 | 544 | | |
| |||
562 | 580 | | |
563 | 581 | | |
564 | 582 | | |
565 | | - | |
| 583 | + | |
566 | 584 | | |
567 | 585 | | |
568 | 586 | | |
| |||
574 | 592 | | |
575 | 593 | | |
576 | 594 | | |
577 | | - | |
| 595 | + | |
578 | 596 | | |
579 | 597 | | |
580 | 598 | | |
| |||
Lines changed: 103 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 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 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
0 commit comments