Skip to content

Commit

Permalink
Make the error message safer
Browse files Browse the repository at this point in the history
  • Loading branch information
jowlyzhang committed Jun 15, 2023
1 parent 15e8a84 commit cb35690
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions env/env_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -328,12 +328,14 @@ class PosixEnv : public CompositeEnv {
}

Status GetHostName(char* name, uint64_t len) override {
int ret = gethostname(name, static_cast<size_t>(len));
const size_t max_len = static_cast<size_t>(len);
int ret = gethostname(name, max_len);
if (ret < 0) {
if (errno == EFAULT || errno == EINVAL) {
return Status::InvalidArgument(errnoStr(errno).c_str());
} else {
return IOError("GetHostName", name, errno);
return IOError("GetHostName", std::string(name, strnlen(name, max_len)),
errno);
}
}
return Status::OK();
Expand Down

0 comments on commit cb35690

Please sign in to comment.