bound destination writes in win32_utf8cpy - #1659
Conversation
michaelrsweet
left a comment
There was a problem hiding this comment.
I probably intended to decrement dstsize, but using an end pointer is more in keeping with our usual coding style.
I would simply initialize dstend to "dst + dstsize - 5" to eliminate the extra checks for capacity. The only callers will be providing a buffer larger than 5 bytes.
Signed-off-by: Aizal Khan <aizumusheer2@gmail.com>
906c879 to
69c40f0
Compare
|
Done. dstend is One thing I noticed re-running the harness: the fixed 5-byte slack means a pure-ASCII name truncates at 252 bytes rather than 255. Output is byte-identical below that, and the overflow is gone either way, so it seems the right trade for dropping the checks. ASan on the extracted function is clean at 599 chars into a 256-byte buffer. |
|
When converting many of the DNS-SD values, some have a hard limit of 63 bytes (size of one DNS label), others might be up to 4 labels (252 bytes) in length, so we are good with that limit... :) Thanks! |
Auditing the DNS-SD backends.
win32_utf8cpytakes adstsizebut never touches it, sowhile (*src && dstsize > 4)is a one-time check that the buffer started out bigger than 4 bytes, not a running bound. The loop then stops only at the source nul.Lifted the function out and gave it a 599-character name against a 256-byte buffer:
All six callers pass
char[256]stack buffers holding strings that came off the wire.win32_browse_cbcopies the PTR target of a browse reply intofullname[256];win32_resolve_cbcopies the instance name, the hostname, and every TXT key and value. A responder answering an_ipp._tcp.localbrowse with a long name walks straight past the buffer.win32_wstrcpydirectly below keeps its own counter, andcupsDNSSDSeparateFullNameguards each store withptr < end, so the shape was already there. Bounded each encoding branch againstdstendthe same way. In-range output is byte-identical and the full 255 bytes are still used.