diff --git a/CHANGELOG.md b/CHANGELOG.md index 3129d6170..a5c8b9859 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,16 @@ Versioning](http://semver.org/spec/v2.0.0.html) except to the first release. ### Fixed +## [1.12.2] - 2024-01-11 + +The patch release with fixes from the master branch. + +### Fixed + +- Tests with crud 1.4.0 (#336) +- Tests with case sensitive SQL (#341) +- Potentially packet length overflow when reading (#361) + ## [1.12.1] - 2023-08-03 The patch release with fixes from the master branch. diff --git a/Makefile b/Makefile index cc689dae7..49e91a5ce 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ clean: .PHONY: deps deps: clean ( cd ./queue/testdata; $(TTCTL) rocks install queue 1.3.0 ) - ( cd ./crud/testdata; $(TTCTL) rocks install crud 1.1.1 ) + ( cd ./crud/testdata; $(TTCTL) rocks install crud 1.4.1 ) .PHONY: datetime-timezones datetime-timezones: diff --git a/connection.go b/connection.go index 055941e78..60cad18d5 100644 --- a/connection.go +++ b/connection.go @@ -1190,7 +1190,7 @@ func (conn *Connection) timeouts() { } func read(r io.Reader, lenbuf []byte) (response []byte, err error) { - var length int + var length uint64 if _, err = io.ReadFull(r, lenbuf); err != nil { return @@ -1199,15 +1199,20 @@ func read(r io.Reader, lenbuf []byte) (response []byte, err error) { err = errors.New("Wrong response header") return } - length = (int(lenbuf[1]) << 24) + - (int(lenbuf[2]) << 16) + - (int(lenbuf[3]) << 8) + - int(lenbuf[4]) + length = (uint64(lenbuf[1]) << 24) + + (uint64(lenbuf[2]) << 16) + + (uint64(lenbuf[3]) << 8) + + uint64(lenbuf[4]) - if length == 0 { - err = errors.New("Response should not be 0 length") + switch { + case length == 0: + err = errors.New("response should not be 0 length") + return + case length > math.MaxUint32: + err = errors.New("response is too big") return } + response = make([]byte, length) _, err = io.ReadFull(r, response) diff --git a/crud/tarantool_test.go b/crud/tarantool_test.go index 0787c99e5..af20b8aa3 100644 --- a/crud/tarantool_test.go +++ b/crud/tarantool_test.go @@ -227,7 +227,7 @@ var testResultWithErrCases = []struct { { "ManyResult", &crud.Result{}, - crud.MakeReplaceManyRequest(invalidSpaceName).Opts(opManyOpts), + crud.MakeReplaceManyRequest(invalidSpaceName).Tuples(tuples).Opts(opManyOpts), }, { "NumberResult", diff --git a/settings/tarantool_test.go b/settings/tarantool_test.go index 054d5052a..268001600 100644 --- a/settings/tarantool_test.go +++ b/settings/tarantool_test.go @@ -116,7 +116,7 @@ func TestSQLDefaultEngineSetting(t *testing.T) { require.Equal(t, []interface{}{[]interface{}{"sql_default_engine", "vinyl"}}, resp.Data) // Create a space with "CREATE TABLE". - resp, err = conn.Execute("CREATE TABLE t1_vinyl(a INT PRIMARY KEY, b INT, c INT);", []interface{}{}) + resp, err = conn.Execute("CREATE TABLE T1_VINYL(a INT PRIMARY KEY, b INT, c INT);", []interface{}{}) require.Nil(t, err) require.NotNil(t, resp) require.Equal(t, uint64(1), resp.SQLInfo.AffectedCount) @@ -140,7 +140,7 @@ func TestSQLDefaultEngineSetting(t *testing.T) { require.Equal(t, []interface{}{[]interface{}{"sql_default_engine", "memtx"}}, resp.Data) // Create a space with "CREATE TABLE". - resp, err = conn.Execute("CREATE TABLE t2_memtx(a INT PRIMARY KEY, b INT, c INT);", []interface{}{}) + resp, err = conn.Execute("CREATE TABLE T2_MEMTX(a INT PRIMARY KEY, b INT, c INT);", []interface{}{}) require.Nil(t, err) require.NotNil(t, resp) require.Equal(t, uint64(1), resp.SQLInfo.AffectedCount) @@ -233,13 +233,13 @@ func TestSQLFullColumnNamesSetting(t *testing.T) { defer conn.Close() // Create a space. - resp, err = conn.Execute("CREATE TABLE fkname(id INT PRIMARY KEY, x INT);", []interface{}{}) + resp, err = conn.Execute("CREATE TABLE FKNAME(ID INT PRIMARY KEY, X INT);", []interface{}{}) require.Nil(t, err) require.NotNil(t, resp) require.Equal(t, uint64(1), resp.SQLInfo.AffectedCount) // Fill it with some data. - resp, err = conn.Execute("INSERT INTO fkname VALUES (1, 1);", []interface{}{}) + resp, err = conn.Execute("INSERT INTO FKNAME VALUES (1, 1);", []interface{}{}) require.Nil(t, err) require.NotNil(t, resp) require.Equal(t, uint64(1), resp.SQLInfo.AffectedCount) @@ -257,7 +257,7 @@ func TestSQLFullColumnNamesSetting(t *testing.T) { require.Equal(t, []interface{}{[]interface{}{"sql_full_column_names", false}}, resp.Data) // Get a data with short column names in metadata. - resp, err = conn.Execute("SELECT x FROM fkname WHERE id = 1;", []interface{}{}) + resp, err = conn.Execute("SELECT X FROM FKNAME WHERE ID = 1;", []interface{}{}) require.Nil(t, err) require.NotNil(t, resp) require.Equal(t, "X", resp.MetaData[0].FieldName) @@ -275,7 +275,7 @@ func TestSQLFullColumnNamesSetting(t *testing.T) { require.Equal(t, []interface{}{[]interface{}{"sql_full_column_names", true}}, resp.Data) // Get a data with full column names in metadata. - resp, err = conn.Execute("SELECT x FROM fkname WHERE id = 1;", []interface{}{}) + resp, err = conn.Execute("SELECT X FROM FKNAME WHERE ID = 1;", []interface{}{}) require.Nil(t, err) require.NotNil(t, resp) require.Equal(t, "FKNAME.X", resp.MetaData[0].FieldName) diff --git a/tarantool_test.go b/tarantool_test.go index 39e9c3511..bde48adf2 100644 --- a/tarantool_test.go +++ b/tarantool_test.go @@ -1324,17 +1324,18 @@ func TestClientSessionPush(t *testing.T) { } const ( - createTableQuery = "CREATE TABLE SQL_SPACE (id STRING PRIMARY KEY, name STRING COLLATE \"unicode\" DEFAULT NULL);" + createTableQuery = "CREATE TABLE SQL_SPACE (ID STRING PRIMARY KEY, NAME " + + "STRING COLLATE \"unicode\" DEFAULT NULL);" insertQuery = "INSERT INTO SQL_SPACE VALUES (?, ?);" - selectNamedQuery = "SELECT id, name FROM SQL_SPACE WHERE id=:id AND name=:name;" - selectPosQuery = "SELECT id, name FROM SQL_SPACE WHERE id=? AND name=?;" - updateQuery = "UPDATE SQL_SPACE SET name=? WHERE id=?;" + selectNamedQuery = "SELECT ID, NAME FROM SQL_SPACE WHERE ID=:ID AND NAME=:NAME;" + selectPosQuery = "SELECT ID, NAME FROM SQL_SPACE WHERE ID=? AND NAME=?;" + updateQuery = "UPDATE SQL_SPACE SET NAME=? WHERE ID=?;" enableFullMetaDataQuery = "SET SESSION \"sql_full_metadata\" = true;" - selectSpanDifQueryNew = "SELECT id||id, name, id FROM seqscan SQL_SPACE WHERE name=?;" - selectSpanDifQueryOld = "SELECT id||id, name, id FROM SQL_SPACE WHERE name=?;" + selectSpanDifQueryNew = "SELECT ID||ID, NAME, ID FROM seqscan SQL_SPACE WHERE NAME=?;" + selectSpanDifQueryOld = "SELECT ID||ID, NAME, ID FROM SQL_SPACE WHERE NAME=?;" alterTableQuery = "ALTER TABLE SQL_SPACE RENAME TO SQL_SPACE2;" insertIncrQuery = "INSERT INTO SQL_SPACE2 VALUES (?, ?);" - deleteQuery = "DELETE FROM SQL_SPACE2 WHERE name=?;" + deleteQuery = "DELETE FROM SQL_SPACE2 WHERE NAME=?;" dropQuery = "DROP TABLE SQL_SPACE2;" dropQuery2 = "DROP TABLE SQL_SPACE;" disableFullMetaDataQuery = "SET SESSION \"sql_full_metadata\" = false;" @@ -1383,8 +1384,8 @@ func TestSQL(t *testing.T) { { selectNamedQuery, map[string]interface{}{ - "id": "1", - "name": "test", + "ID": "1", + "NAME": "test", }, Response{ SQLInfo: SQLInfo{AffectedCount: 0}, @@ -1434,14 +1435,14 @@ func TestSQL(t *testing.T) { FieldName: "COLUMN_1", FieldIsNullable: false, FieldIsAutoincrement: false, - FieldSpan: "id||id", + FieldSpan: "ID||ID", }, { FieldType: "string", FieldName: "NAME", FieldIsNullable: true, FieldIsAutoincrement: false, - FieldSpan: "name", + FieldSpan: "NAME", FieldCollation: "unicode", }, { @@ -1449,7 +1450,7 @@ func TestSQL(t *testing.T) { FieldName: "ID", FieldIsNullable: false, FieldIsAutoincrement: false, - FieldSpan: "id", + FieldSpan: "ID", FieldCollation: "", }, }},