From 21cf5016d98ff568692e91751d021facbdfc6bb6 Mon Sep 17 00:00:00 2001 From: Jeff Halter <868228+jhalter@users.noreply.github.com> Date: Fri, 29 May 2026 08:22:49 -0700 Subject: Guard against panics from unchecked type assertions Replace two unchecked type assertions that could crash the server: - server.go: the file-transfer logger built remoteAddr via a bare ctx.Value(contextKeyReq).(requestCtx) assertion, which panics if the context value is absent or the wrong type. Use the comma-ok form and degrade to an empty string. - access.go: the legacy (< v0.17.0) AccessBitmap YAML array path used byte(v.(int)) with no element-type or bounds check, panicking on a non-int element or an array longer than the [8]byte bitmap. Iterate the slice from the type switch, bounds-check the index, and comma-ok each element, returning a wrapped error so a malformed user file fails to load loudly instead of crashing the server. Add regression tests for the non-int and oversized legacy array cases. --- hotline/access_test.go | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'hotline/access_test.go') diff --git a/hotline/access_test.go b/hotline/access_test.go index 2c5b8f4..65d29be 100644 --- a/hotline/access_test.go +++ b/hotline/access_test.go @@ -74,6 +74,16 @@ func Test_accessBitmap_UnmarshalYAML(t *testing.T) { expected: AccessBitmap{96, 112, 12, 32, 3, 128, 0, 0}, wantErr: false, }, + { + name: "legacy array with non-int element returns error", + yamlData: `access: [96, "nope", 12, 32, 3, 128, 0, 0]`, + wantErr: true, + }, + { + name: "legacy array with too many elements returns error", + yamlData: "access: [1, 2, 3, 4, 5, 6, 7, 8, 9]", + wantErr: true, + }, { name: "unmarshal map format with true values", yamlData: `access: -- cgit