From: Shawn Routhier Date: Tue, 22 Sep 2015 00:21:30 +0000 (-0700) Subject: [trac4001] Clear errno before calling OS functions X-Git-Tag: trac4045_base~4^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=46dda2895ea38d8c6dbdc26112565201401f14f4;p=thirdparty%2Fkea.git [trac4001] Clear errno before calling OS functions --- diff --git a/src/hooks/dhcp/user_chk/load_unload.cc b/src/hooks/dhcp/user_chk/load_unload.cc index 4bba46e8e1..20ed539ce0 100644 --- a/src/hooks/dhcp/user_chk/load_unload.cc +++ b/src/hooks/dhcp/user_chk/load_unload.cc @@ -74,6 +74,10 @@ extern "C" { int load(LibraryHandle&) { // non-zero indicates an error. int ret_val = 0; + + // zero out the errno to be safe + errno = 0; + try { // Instantiate the registry. user_registry.reset(new UserRegistry()); diff --git a/src/lib/cc/data.cc b/src/lib/cc/data.cc index 53d22b38b2..f567c7d185 100644 --- a/src/lib/cc/data.cc +++ b/src/lib/cc/data.cc @@ -731,6 +731,9 @@ Element::fromJSON(const std::string& in, bool preproc) { ElementPtr Element::fromJSONFile(const std::string& file_name, bool preproc) { + // zero out the errno to be safe + errno = 0; + std::ifstream infile(file_name.c_str(), std::ios::in | std::ios::binary); if (!infile.is_open()) { diff --git a/src/lib/config/module_spec.cc b/src/lib/config/module_spec.cc index da42a5e282..f3fb64455c 100644 --- a/src/lib/config/module_spec.cc +++ b/src/lib/config/module_spec.cc @@ -1,4 +1,4 @@ -// Copyright (C) 2010, 2011 Internet Systems Consortium. +// Copyright (C) 2010, 2011, 2015 Internet Systems Consortium. // // Permission to use, copy, modify, and distribute this software for any // purpose with or without fee is hereby granted, provided that the above @@ -311,6 +311,9 @@ moduleSpecFromFile(const std::string& file_name, const bool check) { std::ifstream file; + // zero out the errno to be safe + errno = 0; + file.open(file_name.c_str()); if (!file) { std::stringstream errs; diff --git a/src/lib/dhcp/iface_mgr.cc b/src/lib/dhcp/iface_mgr.cc index d1089269e6..b61aac0639 100644 --- a/src/lib/dhcp/iface_mgr.cc +++ b/src/lib/dhcp/iface_mgr.cc @@ -810,6 +810,10 @@ IfaceMgr::getLocalAddress(const IOAddress& remote_addr, const uint16_t port) { // @todo: We don't specify interface in any way here. 255.255.255.255 // We can very easily end up with a socket working on a different // interface. + + // zero out the errno to be safe + errno = 0; + sock.open(asio::ip::udp::v4(), err_code); if (err_code) { const char* errstr = strerror(errno); @@ -927,6 +931,9 @@ IfaceMgr::receive4(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */) { select_timeout.tv_sec = timeout_sec; select_timeout.tv_usec = timeout_usec; + // zero out the errno to be safe + errno = 0; + int result = select(maxfd + 1, &sockets, NULL, NULL, &select_timeout); if (result == 0) { @@ -1034,6 +1041,9 @@ Pkt6Ptr IfaceMgr::receive6(uint32_t timeout_sec, uint32_t timeout_usec /* = 0 */ select_timeout.tv_sec = timeout_sec; select_timeout.tv_usec = timeout_usec; + // zero out the errno to be safe + errno = 0; + int result = select(maxfd + 1, &sockets, NULL, NULL, &select_timeout); if (result == 0) { diff --git a/src/lib/log/compiler/message.cc b/src/lib/log/compiler/message.cc index f69e3539a0..535f5c0c88 100644 --- a/src/lib/log/compiler/message.cc +++ b/src/lib/log/compiler/message.cc @@ -276,6 +276,9 @@ writeHeaderFile(const string& file, const vector& ns_components, // Text to use as the sentinels. string sentinel_text = sentinel(header_file); + // zero out the errno to be safe + errno = 0; + // Open the output file for writing ofstream hfile(header_file.fullName().c_str()); @@ -378,6 +381,9 @@ writeProgramFile(const string& file, const vector& ns_components, program_file.setDirectory(output_directory); } + // zero out the errno to be safe + errno = 0; + // Open the output file for writing ofstream ccfile(program_file.fullName().c_str());