Commit 813bf6f
fix: bound HTTP camera response header copies to prevent buffer overflow
RemoteCameraHTTP::GetResponse()'s non-PCRE parser (the default when built
without PCRE) copied server-controlled HTTP response header values into
fixed-size static buffers with unbounded strcpy()/sprintf(), and with
strncpy() bounds derived from delimiters rather than the buffer size. A
malicious or MitM'd HTTP camera could overflow status_mesg[256],
connection_type[32], content_type[32] and content_boundary[64],
corrupting adjacent parser state (content_length, content_boundary_len)
for DoS and secondary heap corruption.
Add zm_strncpy(): a bounded copy that always null-terminates (strcpy
overflows; strncpy skips the terminator on truncation) and optionally
caps to a field length n for delimiter-bounded values whose source is
not null-terminated at the field end. Route every header copy in
GetResponse() through it. The content_boundary "--" prefix is written
separately and content_boundary_len is taken from strlen() of the
resulting (now bounded) string so the compare length at the multipart
subheader match stays correct.
The two subcontent-header strncpy() calls were already bounded to
sizeof-1 with an explicit terminator and are left as-is.
Adds a tests/zm_utils.cpp self-check covering fit, truncation,
delimiter-limit, delimiter-over-buffer, and empty-source cases.
Refs GHSA-93j4-rcp9-9jx6.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>1 parent 0b27b67 commit 813bf6f
3 files changed
Lines changed: 51 additions & 13 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
719 | 719 | | |
720 | 720 | | |
721 | 721 | | |
722 | | - | |
723 | | - | |
724 | | - | |
| 722 | + | |
725 | 723 | | |
726 | 724 | | |
727 | 725 | | |
728 | 726 | | |
729 | 727 | | |
730 | | - | |
731 | | - | |
| 728 | + | |
732 | 729 | | |
733 | 730 | | |
734 | 731 | | |
735 | 732 | | |
736 | | - | |
| 733 | + | |
737 | 734 | | |
738 | 735 | | |
739 | 736 | | |
| |||
771 | 768 | | |
772 | 769 | | |
773 | 770 | | |
774 | | - | |
775 | 771 | | |
776 | | - | |
777 | | - | |
| 772 | + | |
778 | 773 | | |
779 | 774 | | |
780 | 775 | | |
| |||
786 | 781 | | |
787 | 782 | | |
788 | 783 | | |
789 | | - | |
| 784 | + | |
790 | 785 | | |
791 | 786 | | |
792 | 787 | | |
793 | 788 | | |
794 | 789 | | |
795 | 790 | | |
796 | 791 | | |
797 | | - | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
798 | 795 | | |
799 | 796 | | |
800 | 797 | | |
801 | 798 | | |
802 | 799 | | |
803 | | - | |
| 800 | + | |
804 | 801 | | |
805 | 802 | | |
806 | 803 | | |
| |||
940 | 937 | | |
941 | 938 | | |
942 | 939 | | |
943 | | - | |
| 940 | + | |
944 | 941 | | |
945 | 942 | | |
946 | 943 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
32 | 32 | | |
33 | 33 | | |
34 | 34 | | |
| 35 | + | |
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| |||
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
46 | 60 | | |
47 | 61 | | |
48 | 62 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
330 | 330 | | |
331 | 331 | | |
332 | 332 | | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
0 commit comments