]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[trac4001] Clear errno before calling OS functions
authorShawn Routhier <sar@isc.org>
Tue, 22 Sep 2015 00:21:30 +0000 (17:21 -0700)
committerShawn Routhier <sar@isc.org>
Tue, 22 Sep 2015 00:21:30 +0000 (17:21 -0700)
src/hooks/dhcp/user_chk/load_unload.cc
src/lib/cc/data.cc
src/lib/config/module_spec.cc
src/lib/dhcp/iface_mgr.cc
src/lib/log/compiler/message.cc

index 4bba46e8e1dc8b6e35b6527a71e182c2fbfe614a..20ed539ce07b76017257d338cd162b1f52166d0a 100644 (file)
@@ -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());
index 53d22b38b2948751798dcf53e78d653aba798491..f567c7d185a1455e550bc66d8daf4d171217ff25 100644 (file)
@@ -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())
     {
index da42a5e282d8259280d76c213ef56b169e19db9b..f3fb64455cf21fa9078fd365e228ecee1ef7802d 100644 (file)
@@ -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;
index d1089269e6df7f87067affd587cdf00d7694970c..b61aac0639ce342656c4cdfff84a2a72468fb69b 100644 (file)
@@ -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) {
index f69e3539a0f31893a098bcf2e80f5a5279752509..535f5c0c88fb09cc8d15407b00186b4d010cd120 100644 (file)
@@ -276,6 +276,9 @@ writeHeaderFile(const string& file, const vector<string>& 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<string>& 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());