Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix typing for alertErrors #627

Merged
merged 2 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -625,13 +625,8 @@
hasHandshake = true
}

var e *alertError
if errors.As(err, &e) {
if e.IsFatalOrCloseNotify() {
return e
}
} else if err != nil {
return e
if err != nil {
return err
}
}
if hasHandshake {
Expand Down Expand Up @@ -666,7 +661,7 @@
return e
}
} else if err != nil {
return e
return err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is the same situation as on L610, the additional checking for alertError doesn't do anything. But if this exists on master still then lets fix that there instead.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so. I didn't want to change any behavior so went for the minimal change.

On line 610 the caller checks whether alertError is fatal so we dont need the check here and just return err if it isn't nil.

The caller for line 651 doesn't check if the alertError is fatal so we check it here and suppress alertErrors that are not fatal.

}
}
return nil
Expand Down Expand Up @@ -856,7 +851,7 @@
done := make(chan struct{})
ctxRead, cancelRead := context.WithCancel(context.Background())
c.cancelHandshakeReader = cancelRead
cfg.onFlightState = func(f flightVal, s handshakeState) {

Check warning on line 854 in conn.go

View workflow job for this annotation

GitHub Actions / lint / Go

unused-parameter: parameter 'f' seems to be unused, consider removing or renaming it as _ (revive)
if s == handshakeFinished && !c.isHandshakeCompletedSuccessfully() {
c.setHandshakeCompletedSuccessfully()
close(done)
Expand Down
50 changes: 50 additions & 0 deletions conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@

var msgSeq atomic.Int32
// Send invalid record after first message
caWithInvalidRecord.onWrite = func(b []byte) {

Check warning on line 426 in conn_test.go

View workflow job for this annotation

GitHub Actions / lint / Go

unused-parameter: parameter 'b' seems to be unused, consider removing or renaming it as _ (revive)
if msgSeq.Add(1) == 2 {
if _, err := ca.Write([]byte{0x01, 0x02}); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -3135,3 +3135,53 @@
ca.Close()
<-done
}

func TestApplicationDataWithClientHelloRejected(t *testing.T) {
// Limit runtime in case of deadlocks
lim := test.TimeOut(time.Second * 20)
defer lim.Stop()

// Check for leaking routines
report := test.CheckRoutines(t)
defer report()

ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

ca, cb := dpipe.Pipe()
defer ca.Close()
defer cb.Close()

done := make(chan struct{})
go func() {
if _, err := testServer(ctx, cb, &Config{}, true); err == nil {
t.Error("expected handshake to fail")
}
close(done)
}()
extensions := []extension.Extension{}

time.Sleep(50 * time.Millisecond)

err := sendClientHello([]byte{}, ca, 0, extensions)
if err != nil {
t.Fatal(err)
}

// Send an application data packet
packet, err := (&recordlayer.RecordLayer{
Header: recordlayer.Header{
Version: protocol.Version1_2,
SequenceNumber: uint64(3),
Epoch: 0,
},
Content: &protocol.ApplicationData{
Data: []byte{1, 2, 3, 4},
},
}).Marshal()
if err != nil {
t.Fatal(err)
}
ca.Write(packet)
<-done
}
Loading