|
| 1 | +From 559e062ce8bfd6a39925294620b50906ca2a6f95 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Nicola Murino < [email protected]> |
| 3 | +Date: Sun, 31 Aug 2025 20:07:32 +0200 |
| 4 | +Subject: [PATCH] ssh/agent: return an error for unexpected message types |
| 5 | + |
| 6 | +Previously, receiving an unexpected message type in response to a key |
| 7 | +listing or a signing request could cause a panic due to a failed type |
| 8 | +assertion. |
| 9 | + |
| 10 | +This change adds a default case to the type switch in order to detect |
| 11 | +and explicitly handle unknown or invalid message types, returning a |
| 12 | +descriptive error instead of crashing. |
| 13 | + |
| 14 | +Fixes golang/go#75178 |
| 15 | + |
| 16 | +Change-Id: Icbc3432adc79fe3c56b1ff23c6724d7a6f710f3a |
| 17 | +Reviewed-on: https://go-review.googlesource.com/c/crypto/+/700295 |
| 18 | +Reviewed-by: Roland Shoemaker < [email protected]> |
| 19 | +LUCI-TryBot-Result: Go LUCI < [email protected]> |
| 20 | +Reviewed-by: Michael Pratt < [email protected]> |
| 21 | +Reviewed-by: Jakub Ciolek < [email protected]> |
| 22 | +Upstream patch Reference: https://github.com/golang/crypto/commit/559e062ce8bfd6a39925294620b50906ca2a6f95.patch |
| 23 | +--- |
| 24 | + vendor/golang.org/x/crypto/ssh/agent/client.go | 6 ++++-- |
| 25 | + 1 file changed, 4 insertions(+), 2 deletions(-) |
| 26 | + |
| 27 | +diff --git a/vendor/golang.org/x/crypto/ssh/agent/client.go b/vendor/golang.org/x/crypto/ssh/agent/client.go |
| 28 | +index 106708d..31bd7e8 100644 |
| 29 | +--- a/vendor/golang.org/x/crypto/ssh/agent/client.go |
| 30 | ++++ b/vendor/golang.org/x/crypto/ssh/agent/client.go |
| 31 | +@@ -430,8 +430,9 @@ func (c *client) List() ([]*Key, error) { |
| 32 | + return keys, nil |
| 33 | + case *failureAgentMsg: |
| 34 | + return nil, errors.New("agent: failed to list keys") |
| 35 | ++ default: |
| 36 | ++ return nil, fmt.Errorf("agent: failed to list keys, unexpected message type %T", msg) |
| 37 | + } |
| 38 | +- panic("unreachable") |
| 39 | + } |
| 40 | + |
| 41 | + // Sign has the agent sign the data using a protocol 2 key as defined |
| 42 | +@@ -462,8 +463,9 @@ func (c *client) SignWithFlags(key ssh.PublicKey, data []byte, flags SignatureFl |
| 43 | + return &sig, nil |
| 44 | + case *failureAgentMsg: |
| 45 | + return nil, errors.New("agent: failed to sign challenge") |
| 46 | ++ default: |
| 47 | ++ return nil, fmt.Errorf("agent: failed to list keys, unexpected message type %T", msg) |
| 48 | + } |
| 49 | +- panic("unreachable") |
| 50 | + } |
| 51 | + |
| 52 | + // unmarshal parses an agent message in packet, returning the parsed |
| 53 | +-- |
| 54 | +2.45.4 |
| 55 | + |
0 commit comments