From 8fbd94a6755d97feb61a514777b8c51f7dd775b5 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Mon, 11 Nov 2024 18:07:31 +0100 Subject: [PATCH] Add nil check in UpdateDeadline method Ensure that the connection is not nil before setting the deadline in the UpdateDeadline method. This prevents a potential runtime panic when attempting to set a deadline on a nil connection. --- smtp/smtp.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/smtp/smtp.go b/smtp/smtp.go index ed86ac9..8a278ee 100644 --- a/smtp/smtp.go +++ b/smtp/smtp.go @@ -622,6 +622,9 @@ func (c *Client) HasConnection() bool { func (c *Client) UpdateDeadline(timeout time.Duration) error { c.mutex.Lock() defer c.mutex.Unlock() + if c.conn == nil { + return errors.New("smtp: client has no connection") + } if err := c.conn.SetDeadline(time.Now().Add(timeout)); err != nil { return fmt.Errorf("smtp: failed to update deadline: %w", err) }