windy1 / zeroconf-rs

zeroconf is a cross-platform library that wraps underlying ZeroConf/mDNS implementations such as Bonjour or Avahi, providing an easy and idiomatic way to both register and browse services.
MIT License
76 stars 24 forks source link

Incorrect buffer size allocated for txt record #17

Closed kgrech closed 2 years ago

kgrech commented 2 years ago

Steps to reproduce (Macos Big Sur):

Create MdnsService service and insert a few records.

let mut service = MdnsService::new(service_type, announcer_options.port);
let mut txt_record = TxtRecord::new();
txt_record
    .insert("service-id", ""405d70a5-b17d-438c-a08b-84b3c0573689"")
    .unwrap();
txt_record
    .insert("port", "7787").as_str())
    .unwrap();
service.set_txt_record(txt_record);

On the client side (we are using python library zeroconf v0.36.8 as client) we receive the following:

properties={b'service-id': b'405d70a5-b17d-43', b'port': b'7787\x00\x00\x00\xe0\x07\n\n\xe5\xf9\x07\x00\xf0'}, interface_index=None)

It looks like the side of the property is always equals to 16.

It seems to me that the problem is around this line in TTxtRecord::insert. Maybe it should be

let value_size = mem::size_of_val(value.as_bytes()) as u8;

or probably even

let value_size = value.as_bytes().len();

?

windy1 commented 2 years ago

Sorry this took so long to address, I was able to reproduce the issue and your proposed fix was indeed the solution. You can get it in 0.10.5. Thanks!