Ticket #276: 0001-On-signal-reception-return-EAI_SYSTEM-from-openvpn_g.patch

File 0001-On-signal-reception-return-EAI_SYSTEM-from-openvpn_g.patch, 1.5 KB (added by Gert Döring, 5 years ago)

patch as described

  • src/openvpn/socket.c

    From 8b2aca6221141cce45576115b41f52b3a5084156 Mon Sep 17 00:00:00 2001
    From: Gert Doering <gert@greenie.muc.de>
    Date: Sun, 31 May 2015 20:51:25 +0200
    Subject: [PATCH] On signal reception, return EAI_SYSTEM from
     openvpn_getaddrinfo().
    
    A signal (except SIGUSR1) received while waiting for getaddrinfo() is
    considered fatal, so openvpn_getaddrinfo() is destroying the returned
    information with freeaddrinfo(), but still signalled "success" (0)
    to the caller - so if the caller accessed *res before checking
    *signal_received, it would access just-free()ed memory, which on some
    platforms still worked and on others caused a crash.
    
    Also, ensure that *ai is also NULLed in the caller now.
    
    Signed-off-by: Gert Doering <gert@greenie.muc.de>
    ---
     src/openvpn/socket.c | 5 ++++-
     1 file changed, 4 insertions(+), 1 deletion(-)
    
    diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c
    index cf2dec3..034ccc1 100644
    a b msg(M_INFO, "if(*signal_received)"); 
    219219                    }
    220220                  else
    221221                    {
     222                      /* turn success into failure (interrupted syscall) */
    222223                      if (0 == status) {
    223224                          ASSERT(res);
    224225                          freeaddrinfo(*res);
    225                           res = NULL;
     226                          *res = NULL;
     227                          status = EAI_SYSTEM;
     228                          errno = EINTR;
    226229                      }
    227230                      goto done;
    228231                    }