]> git.ipfire.org Git - thirdparty/openvpn.git/commit
Fix handling of out of memory error in interactive service
authorSelva Nair <selva.nair@gmail.com>
Sun, 22 May 2016 18:39:32 +0000 (14:39 -0400)
committerGert Doering <gert@greenie.muc.de>
Sun, 22 May 2016 20:34:40 +0000 (22:34 +0200)
commit600dd9a16fc61ff6e595f500fba5daf14248b739
tree3f9cca69a1a57a8e89a6d42575de41c7c2e258e6
parent698f0dab76741f4ce8c1a98236786d59eca338ef
Fix handling of out of memory error in interactive service

Currently realloc failure in UpdateWaitHandles() is handled by
triggering exit_event and waiting for all active worker threads
to terminate. However, at this point the wait handles array
will contain an invalid value (handle of the latest thread that
is terminated), causing a cycle of WAIT_FAILED <-> continue and
trashing of the eventlog.

Fix:
- Update the wait handles again after removing the last thread:
  this should not fail as no extra memory is needed. Do not set
  the exit event; existing connections are not terminated.

- In case of WAIT_FAILED, break out of the while loop and exit
  instead of continue. This usually happens when one or more
  handles are invalid, which is hard to recover from.

Other changes:
- Use minimal initial allocation size so that the realloc code path
  gets exercised (2 or more connections will cause realloc).
- Use a temp variable to check the return value of realloc().
- Initialize handles array pointer to NULL.

v2 changes:
- Increased initial allocation to 10 (warn: now 10 or more connections
  needed to exercise the realloc code path).
- Moved up the declaration of "LPHANDLE tmp" to please stone-age MSVC.

Tested using a dummy realloc that returns NULL.

Signed-off-by: Selva Nair <selva.nair@gmail.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <1463942372-26958-1-git-send-email-selva.nair@gmail.com>
URL: http://article.gmane.org/gmane.network.openvpn.devel/11708
Signed-off-by: Gert Doering <gert@greenie.muc.de>
src/openvpnserv/interactive.c