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 532de97
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions env/env_posix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -328,12 +328,16 @@ 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 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();
Expand Down

0 comments on commit 532de97

Please sign in to comment.