Commit ffd773e
committed
v3/control: replace unchecked type asserts in DecodeControl with comma-ok
DecodeControl trusts that every controlType is a string and every
criticality is a bool, and falls back to value.Value.(string) for any
unknown control type. When a malformed or hostile server returns a
non-string (or nil) in any of these positions, the .(string) /
.(bool) cast panics inside the caller's goroutine. The user repro in
#561 hit the default case where value.Value was nil:
panic: interface conversion: interface {} is nil, not string
go-ldap/ldap/v3.DecodeControl(...)
go-ldap/ldap/v3.(*Conn).SimpleBind(...)
Use comma-ok asserts at every control-frame field, return clear
errors when the cast fails, and in the default ControlString case
fall back to value.Data.String() when value.Value isn't a string so
the application gets the bytes instead of a crash.
The existing TestDecodeControl table covers the normal-path cases
and still passes; the new behaviour only kicks in on malformed
input where the previous code panicked.
Closes #561
Signed-off-by: Charlie Tonneslan <cst0520@gmail.com>1 parent bf231eb commit ffd773e
1 file changed
Lines changed: 32 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
565 | 565 | | |
566 | 566 | | |
567 | 567 | | |
568 | | - | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
569 | 573 | | |
570 | 574 | | |
571 | 575 | | |
572 | 576 | | |
573 | | - | |
| 577 | + | |
| 578 | + | |
| 579 | + | |
| 580 | + | |
| 581 | + | |
574 | 582 | | |
575 | 583 | | |
576 | 584 | | |
| |||
579 | 587 | | |
580 | 588 | | |
581 | 589 | | |
582 | | - | |
| 590 | + | |
583 | 591 | | |
584 | | - | |
| 592 | + | |
585 | 593 | | |
586 | 594 | | |
587 | 595 | | |
588 | 596 | | |
589 | 597 | | |
590 | 598 | | |
591 | 599 | | |
592 | | - | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
593 | 605 | | |
594 | 606 | | |
595 | | - | |
| 607 | + | |
| 608 | + | |
| 609 | + | |
| 610 | + | |
| 611 | + | |
596 | 612 | | |
597 | 613 | | |
598 | 614 | | |
| |||
729 | 745 | | |
730 | 746 | | |
731 | 747 | | |
732 | | - | |
| 748 | + | |
| 749 | + | |
| 750 | + | |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
| 755 | + | |
| 756 | + | |
| 757 | + | |
733 | 758 | | |
734 | 759 | | |
735 | 760 | | |
| |||
0 commit comments