]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[805] Misc fixes
authorMichal 'vorner' Vaner <michal.vaner@nic.cz>
Thu, 5 Jan 2012 19:35:43 +0000 (20:35 +0100)
committerMichal 'vorner' Vaner <michal.vaner@nic.cz>
Thu, 5 Jan 2012 19:35:43 +0000 (20:35 +0100)
* Close the socket after sending from the creator, so it doesn't leak
  (but it doesn't seem to help :-().
* Correct range for the token numbers, so they are harder to guess
* Set the socket as reuse address

src/bin/sockcreator/sockcreator.cc
src/lib/python/isc/bind10/socket_cache.py

index 6b50813f4fffea2d84af821002cd76160ae033ee..420fde7c7fc9ec518e6a9010571d2979153f311c 100644 (file)
@@ -35,6 +35,10 @@ get_sock(const int type, struct sockaddr *bind_addr, const socklen_t addr_len)
     if (sock == -1) {
         return -1;
     }
+    const int on(1);
+    if (setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &on, sizeof(on)) == -1) {
+        return -2; // This is part of the binding process, so it's a bind error
+    }
     if (bind(sock, bind_addr, addr_len) == -1) {
         return -2;
     }
@@ -124,6 +128,8 @@ run(const int input_fd, const int output_fd, const get_sock_t get_sock,
                     WRITE("S", 1);
                     // FIXME: Check the output and write a test for it
                     send_fd(output_fd, result);
+                    // Don't leak the socket
+                    close(result);
                 } else {
                     WRITE("E", 1);
                     switch (result) {
index 26e87d205b4f60387820c83fac209ae2ce9e76cb..d6c117584e18af47758dae0763fbe2b625b6bff3 100644 (file)
@@ -205,9 +205,9 @@ class Cache:
             raise ShareError("Cached socket not compatible with mode " +
                              share_mode + " and name " + share_name)
         # Grab yet unused token
-        token = 't' + str(random.randint(0, 2^32-1))
+        token = 't' + str(random.randint(0, 2 ** 32-1))
         while token in self._live_tokens:
-            token = 't' + str(random.randint(0, 2^32-1))
+            token = 't' + str(random.randint(0, 2 ** 32-1))
         self._waiting_tokens[token] = socket
         self._live_tokens.add(token)
         socket.shares[token] = (share_mode, share_name)