diff --git a/env/env_posix.cc b/env/env_posix.cc index 77f28e1f50ee..07f5ee98a918 100644 --- a/env/env_posix.cc +++ b/env/env_posix.cc @@ -328,12 +328,16 @@ class PosixEnv : public CompositeEnv { } Status GetHostName(char* name, uint64_t len) override { - int ret = gethostname(name, static_cast(len)); + const size_t max_len = static_cast(len); + int ret = gethostname(name, max_len); if (ret < 0) { if (errno == EFAULT || errno == EINVAL) { return Status::InvalidArgument(errnoStr(errno).c_str()); + } else if (errno == ENAMETOOLONG) { + return IOError("GetHostName", std::string(name, strnlen(name, max_len)), + errno); } else { - return IOError("GetHostName", name, errno); + return IOError("GetHostName", "", errno); } } return Status::OK();