From da236f15b1360bced8f4ead25df9c87dc6f99d59 Mon Sep 17 00:00:00 2001
From: chrysn <chrysn@fsfe.org>
Date: Tue, 7 May 2024 00:53:20 +0200
Subject: [PATCH] resetPeer: Don't segfault when called twice

---
 DTLSSocket/dtls.pyx | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/DTLSSocket/dtls.pyx b/DTLSSocket/dtls.pyx
index 813060c..013e866 100644
--- a/DTLSSocket/dtls.pyx
+++ b/DTLSSocket/dtls.pyx
@@ -242,7 +242,9 @@ cdef class DTLS:
   #dtls_peer_t *dtls_get_peer(const dtls_context_t *context, const session_t *session);
   #void dtls_reset_peer(dtls_context_t *ctx, dtls_peer_t *peer)
   def resetPeer(self, Session session: Session):
-    tdtls.dtls_reset_peer(self.ctx, tdtls.dtls_get_peer(self.ctx, session.getSession()))
+    peer = tdtls.dtls_get_peer(self.ctx, &session.session)
+    if peer:
+      tdtls.dtls_reset_peer(self.ctx, peer)
 
   #int dtls_write(dtls_context_t *ctx, session_t *session, uint8 *buf, size_t len)
   def write(self, Session remote: Session, data: bytes):
-- 
GitLab