Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Handle posix hostname edge cases (#14)
* Handle extra nul byte HOST_NAME_MAX is the maximum allowed hostname excluding the terminating nul byte. This means that HOST_NAME_MAX + 1 must be used for gethostname call. Otherwise -1 may be returned, e.g. by glibc's gethostname. How to reproduce on Linux with glibc: - Set hostname to a 64 character long string - Try to retrieve hostname * Handle posix systems without HOST_NAME_MAX limits If sysconf returns -1 this either means that an error occurred or that no limit exists. Casting -1 to size_t leads to a huge number, so only use the returned limit if it is not -1. If sysconf returned an error or no limit exists, use 255. * Fail if hostname is too long Invalid hostnames supplied to set should be rejected. Otherwise it could happen that on FreeBSD a partial hostname is set.
- Loading branch information