p2p-server: Only read 32 bytes from /var/lib/dbus/machine-id

At startup, p2p-server emits this error via syslog

 2013-07-02T12:06:18.036161-07:00 localhost p2p-server: Error reading from /var/lib/dbus/machine-id, num_read=33 [service_publisher.cc:130]

This happens because the /var/lib/dbus/machine-id file can contain a
new-line so its file size ends up being 33 bytes and we read these 33
bytes into an array that is only 33 bytes long. This in turn means
there is no terminating NUL byte. Things more or less work anyway
since p2p-server ends up using the machine-id + newline as the service
name and the following byte usually is a NUL byte anyway.

The problem can easily be identified by running avahi-discover(1) on a
machine on the same LAN and inspecting that its output, for example

 Found service '52b9e689edb6049ac025162a51d324a3
 ' of type '_cros_p2p._tcp' in domain 'local' on 3.0.

contains the newline in the service name.

This problem is fixed by simply reading at most 32 bytes from the
machine-id file and ensuring that the buffer we read into is NUL

TEST=Ran avahi-discover(1) and check there's no newline in the service name

Change-Id: If96fda59207cd2584a4bb69eb6cafbf4ba6a3516
Reviewed-on: https://gerrit.chromium.org/gerrit/60799
Reviewed-by: Alex Deymo <deymo@chromium.org>
Tested-by: David Zeuthen <zeuthen@chromium.org>
Commit-Queue: David Zeuthen <zeuthen@chromium.org>
1 file changed