Skip to content

Commit

Permalink
Avoid recursion in virtual_output_callback_func()
Browse files Browse the repository at this point in the history
This solves a SEGV situation when using the management API while OpenVPN
is closing down.

The situation happens when the management socket has closed and OpenVPN
tries to write an error about this to the management socket.  What happens
is that

 virtual_output_callback_func() is called, which then calls
 -> man_output_list_push_finalize()
    -> man_output_standalone()
       -> man_write()  <-- this does the socket write
          -> man_io_error()
             -> x_msg()
                -> virtual_output_print()
                   -> virtual_output_callback_func() (recursion start)

virtual_output_callback_func() do have a mechanism to avoid recursion,
but that did not keep the recurse counter when
man_output_list_push_finalize()
is called.

This patch just reorganise the recursion block to also keep the counter
while
calling the other functions from virtual_output_callback_func()

Signed-off-by: David Sommerseth <davids@redhat.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: 1353063726-25113-1-git-send-email-dazo@users.sourceforge.net
URL: http://article.gmane.org/gmane.network.openvpn.devel/7130
  • Loading branch information
David Sommerseth committed Nov 29, 2012
1 parent feca090 commit b2b6617
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions src/openvpn/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,13 @@ virtual_output_callback_func (void *arg, const unsigned int flags, const char *s

# define AF_DID_PUSH (1<<0)
# define AF_DID_RESET (1<<1)
unsigned int action_flags = 0;

if (!recursive_level) /* don't allow recursion */
{
struct gc_arena gc = gc_new ();
struct log_entry e;
const char *out = NULL;
unsigned int action_flags = 0;

++recursive_level;

Expand Down Expand Up @@ -334,14 +334,15 @@ virtual_output_callback_func (void *arg, const unsigned int flags, const char *s
}
}

--recursive_level;
gc_free (&gc);
}

if (action_flags & AF_DID_PUSH)
man_output_list_push_finalize (man);
if (action_flags & AF_DID_RESET)
man_reset_client_socket (man, true);
if (action_flags & AF_DID_PUSH)
man_output_list_push_finalize (man);
if (action_flags & AF_DID_RESET)
man_reset_client_socket (man, true);

--recursive_level;
}
}

/*
Expand Down

0 comments on commit b2b6617

Please sign in to comment.