Skip to content

Commit

Permalink
iiod: dns-sd: Fix invalid check of hostname vs. "none" string
Browse files Browse the repository at this point in the history
By doing: strncmp(host, "none", sizeof("none") - 1)

We actually only check that the first 4 characters are "none"; as a
result, a "none_foobar.local" hostname would match as well.

The solution is to match the ending \0 as well:
strncmp(host, "none", sizeof("none"))

which can be simplified to just strcmp(host, "none")

Signed-off-by: Paul Cercueil <[email protected]>
  • Loading branch information
pcercuei committed Apr 9, 2021
1 parent 5515b11 commit c25a20f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion iiod/dns-sd.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ static void start_avahi_thd(struct thread_pool *pool, void *d)
while(true) {
ret = gethostname(host, sizeof(host));
IIO_ERROR("host %s\n", host);
if (ret || !strncmp(host, "none", sizeof("none") - 1))
if (ret || !strcmp(host, "none"))
goto again;

iio_snprintf(label, sizeof(label), "%s%s", IIOD_ON, host);
Expand Down

0 comments on commit c25a20f

Please sign in to comment.