Skip to content

Commit

Permalink
Fixed the build (#449)
Browse files Browse the repository at this point in the history
Some linux releases have turned on _FORTIFY_SOURCE=2, which broke our build. This PR tries to fix it
  • Loading branch information
sherman-the-tank authored and laura-ding committed May 30, 2019
1 parent 58d58a4 commit 29c95b4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/common/base/Configuration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ Status Configuration::parseFromFile(const std::string &filename) {
// read the whole content
// TODO(dutor) ::read might be interrupted by signals
auto buffer = std::make_unique<char[]>(len + 1);
::read(fd, buffer.get(), len);
auto charsRead = ::read(fd, buffer.get(), len);
UNUSED(charsRead);
buffer[len] = '\0';
// strip off all comments
static const std::regex comment("//.*|#.*");
Expand Down
11 changes: 10 additions & 1 deletion src/common/network/NetworkUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,16 @@ bool NetworkUtils::getDynamicPortRange(uint16_t& low, uint16_t& high) {
return false;
}

fscanf(pipe, "%hu %hu", &low, &high);
if (fscanf(pipe, "%hu %hu", &low, &high) != 2) {
LOG(ERROR) << "Failed to read from /proc/sys/net/ipv4/ip_local_port_range";
// According to ICANN, the port range is devided into three sections
//
// Well-known ports: 0 to 1023 (used for system services)
// Registered/user ports: 1024 to 49151
// Dynamic/private ports: 49152 to 65535
low = 49152;
high = 65535;
}

if (pclose(pipe) < 0) {
LOG(ERROR) << "Failed to close the pipe: " << strerror(errno);
Expand Down
3 changes: 2 additions & 1 deletion src/common/network/test/NetworkUtilsTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ TEST(NetworkUtils, getHostname) {

FILE* fp = popen("LD_PRELOAD= hostname | tr -d ['\n']", "r");
char buffer[256];
fgets(buffer, sizeof(buffer), fp);
auto numChars = fgets(buffer, sizeof(buffer), fp);
UNUSED(numChars);
pclose(fp);
EXPECT_EQ(std::string(buffer), hostname);
}
Expand Down
3 changes: 2 additions & 1 deletion src/common/process/test/ProcessTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ TEST(ProcessUtils, getExeCWD) {
auto result = ProcessUtils::getExeCWD();
ASSERT_TRUE(result.ok()) << result.status();
char buffer[PATH_MAX];
::getcwd(buffer, sizeof(buffer));
auto len = ::getcwd(buffer, sizeof(buffer));
UNUSED(len);
ASSERT_EQ(buffer, result.value());
}

Expand Down

0 comments on commit 29c95b4

Please sign in to comment.