summaryrefslogtreecommitdiff
path: root/llmnrd.c
diff options
context:
space:
mode:
authorTobias Klauser <tklauser@distanz.ch>2016-08-02 16:45:07 +0200
committerTobias Klauser <tklauser@distanz.ch>2016-08-02 16:45:07 +0200
commit5939d09f16547ab935d8e3699688ed1817471da5 (patch)
tree5c63ef73d5beb3818d108f20f5261b2dce5c1b2c /llmnrd.c
parentde09cf982772733945dd853bc9a54b7b275af705 (diff)
llmnrd: Use MAXHOSTNAMELEN for hostname buffer and zero-terminate string
Use MAXHOSTNAMELEN defined in sys/param.h to determine the size of the hostname buffer to allocate. Also make sure the string is properly zero-terminated in all cases, as in some cases it might be undefined whether a truncated string is properly terminated. Note: Also remove a TODO comment, as watching for hostname changes at runtime is outside the scope of llmnrd (also, avahi behaves the same). Signed-off-by: Tobias Klauser <tklauser@distanz.ch>
Diffstat (limited to 'llmnrd.c')
-rw-r--r--llmnrd.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/llmnrd.c b/llmnrd.c
index 663d524..48e4030 100644
--- a/llmnrd.c
+++ b/llmnrd.c
@@ -29,6 +29,7 @@
#include <unistd.h>
#include <sys/ioctl.h>
+#include <sys/param.h>
#include "compiler.h"
#include "log.h"
@@ -148,12 +149,12 @@ int main(int argc, char **argv)
register_signal(SIGHUP, signal_handler);
if (!hostname) {
- /* TODO: Consider hostname changing at runtime */
- hostname = xmalloc(255);
- if (gethostname(hostname, 255) != 0) {
+ hostname = xzalloc(MAXHOSTNAMELEN);
+ if (gethostname(hostname, MAXHOSTNAMELEN) != 0) {
log_err("Failed to get hostname");
return EXIT_FAILURE;
}
+ hostname[MAXHOSTNAMELEN - 1] = '\0';
}
if (daemonize) {