Selaa lähdekoodia

conn: ensure that stream is within bounds

Chris Bannister 10 vuotta sitten
vanhempi
commit
9004be2f10
1 muutettua tiedostoa jossa 12 lisäystä ja 0 poistoa
  1. 12 0
      conn.go

+ 12 - 0
conn.go

@@ -10,6 +10,7 @@ import (
 	"errors"
 	"fmt"
 	"io"
+	"io/ioutil"
 	"log"
 	"net"
 	"strconv"
@@ -360,6 +361,17 @@ func (c *Conn) recv() error {
 		return err
 	}
 
+	if head.stream > len(c.calls) {
+		return fmt.Errorf("gocql: frame header stream is beyond call exepected bounds: %d", head.stream)
+	} else if head.stream < 0 {
+		// TODO: handle cassandra event frames, we shouldnt get any currently
+		_, err := io.CopyN(ioutil.Discard, c, int64(head.length))
+		if err != nil {
+			return err
+		}
+		return nil
+	}
+
 	call := &c.calls[head.stream]
 	err = call.framer.readFrame(&head)
 	if err != nil {