jbagg / QtZeroConf

Qt wrapper class for ZeroConf libraries across various platforms.
Other
69 stars 51 forks source link

Fixed handling of TXT records longer than 127 bytes #36

Closed morixhub closed 2 years ago

morixhub commented 4 years ago

While browsing services on Windows (through Bonjour SDK) I discovered that I was unable to browser services if some of them published TXT records longer than 127 bytes (the maximum length of TXT records is actually 255 bytes).

The problem was due to the usage of a signed variable (qint16) while spooling the length of the TXT record out of the buffer, in QZeroConfPrivate::resolverCallback() within bonjour.cpp file. If the length of the record was longer that 127 bytes, then it was interpreted as signed during the conversion to qint16 and hence generated a negative value for variable recLen, thus causing the execution to hang within the function.

Changing the declaration type of recLen from qint16 to uchar fixed the problem.

jbagg commented 4 years ago

Can we use a quint16 instead of uchar?

jbagg commented 4 years ago

or quint8

morixhub commented 4 years ago

quint16 is not good since it does not fix the problem. quint8 instead works.

Probably there is something (at least on MSVC compiler) in the "promotion" from char to quint16 than preserves the sign at some stage... quint8 instead performs a direct cast from char tu quint8 (which is an unsigned char) which is good.

jbagg commented 2 years ago

Cherry picked to master, closing