probonopd / announce

Announce services on the network with Zeroconf/Bonjour with minimal overhead.
15 stars 5 forks source link

fix: do not strcat() to an uninitialized buffer. rather strcpy() to it. #9

Closed gkaindl closed 9 years ago

gkaindl commented 9 years ago

When trying announce on my OpenWRT installation, I noticed it prepending garbage characters to my device's hostname. This is probably the same bug as described in #8.

The reason is that the name gets strcat()ed to an uninitialized buffer when storing the "readablename" version of it. Since this buffer is stack-allocated, it will typically contain garbage data, so the actual hostname gets appended wherever the first random 0-byte happens to be.

Since "readablename" and "hostname" are both used during service registration, all services fail to resolve if those two names do not match. Thus, this isn't just a cosmetic issue, but an app-breaking one.

The fix is to replace the strcat() with a strcpy() – Please note that strncpy() is not needed in this case, since the length of the source string is already limited by the gethostname() call.

probonopd commented 9 years ago

Thanks for spotting this, gkaindl.