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

server: fix COM_FIELD_LIST response bug that make mariadb-client crash during use db #6918

Merged
merged 6 commits into from
Jun 28, 2018
Merged

server: fix COM_FIELD_LIST response bug that make mariadb-client crash during use db #6918

merged 6 commits into from
Jun 28, 2018

Conversation

lysu
Copy link
Contributor

@lysu lysu commented Jun 27, 2018

What have you changed? (mandatory)

column-definitions in COM_FIELD_LIST response need write addition default-values part even though we omit default-values.

and some client like MariaDB-cli(without -A)'s use db will trigger COM_FEILD_LIST and read default-values length bit in response, it will meet fault if we haven't give it.
https://github.com/MariaDB/server/blob/72b6d01848e56a75349d663bc61bbe71f97a280b/sql-common/client.c#L1519

  • dump() add option parameter and pass WithDefaultValues option in handle_field_list()
  • check option and add default values length bit in dump
  • remove unuse DefaultValue DefaultValueLength field from server.ColumnInfo

fix #6622

What are the type of the changes (mandatory)?

The currently defined types are listed below, please pick one of the types for this PR by removing the others:

  • Bug fix (non-breaking change which fixes an issue)

How has this PR been tested (mandatory)?

  • manual tests

This change is Reviewable

@lysu lysu changed the title server: fix COM_FIELD_LIST response. server: fix COM_FIELD_LIST response bug that make mariadb-client coredump crash Jun 27, 2018
@lysu lysu changed the title server: fix COM_FIELD_LIST response bug that make mariadb-client coredump crash server: fix COM_FIELD_LIST response bug that make mariadb-client crash during use db Jun 27, 2018
@shenli
Copy link
Member

shenli commented Jun 27, 2018

Well done!

server/column.go Outdated
// Dump dumps ColumnInfo to bytes.
func (column *ColumnInfo) Dump(buffer []byte) []byte {
func (column *ColumnInfo) Dump(buffer []byte, flags DumpOpt) []byte {
Copy link
Member

Choose a reason for hiding this comment

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

Can we use a bool argument to control whether output default value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done~

server/column.go Outdated
if flags&WithDefaultValue > 0 {
// Current we doesn't output defaultValue but reserve defaultValue length bit to make mariadb client happy.
// https://dev.mysql.com/doc/internals/en/com-query-response.html#column-definition
buffer = dumpUint64(buffer, 0)
Copy link
Member

Choose a reason for hiding this comment

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

why this change works?

Copy link
Contributor Author

@lysu lysu Jun 27, 2018

Choose a reason for hiding this comment

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

because in protocol definition https://dev.mysql.com/doc/internals/en/com-query-response.html#column-definition said.

  if command was COM_FIELD_LIST {
lenenc_int     length of default-values
string[$len]   default values
  }

So, if it's a response of COM_FIELD_LIST, we should actually add default values part use just like this.

+----------------------+-------------------+------------+--------------+--------------+-----------+--------------------+
|                      |                   |            |              |              |           |                    |
|                      |                   |            |              |              |           |                    |
|                      |                   |            |              |              |           |                    |
|                      |                   |            |              |              |           |                    |
|      ....sth we      |  length byte of   |   default  |   default    |   default    |  default  |   ..............   |
|      outputed        |  default values   |   value 1  |   value 2    |   value 3    |  value 4  |                    |
|                      |                   |            |              |              |           |                    |
|                      |                   |            |              |              |           |                    |
|                      |                   |            |              |              |           |                    |
+----------------------+-------------------+------------+--------------+--------------+-----------+--------------------+

but In tidb we omit default values(It seems not easy to output that....), and omit all default values bytes...but mariadb will read length byte of default values without condition, after send COM_FIELD_LIST. see: https://github.com/MariaDB/server/blob/72b6d01848e56a75349d663bc61bbe71f97a280b/sql-common/client.c#L1519

So at this PR, we don't complete fill all default values but follow the protocol give client an empty default values

+-------------+--------------+
|             |              |
|             |              |
|             |              |
|  sth we     | length byte  |
|  outputed   | of default   |
|             | values       |
|             |              |
|             |    (0)       |
|             |              |
+-------------+--------------+

so mariadb will read length byte without out of index crash.

@zz-jason
Copy link
Member

:lgtm:


Review status: 0 of 4 files reviewed, 1 unresolved discussion (waiting on @shenli, @tiancaiamao, and @coocood)


Comments from Reviewable

@tiancaiamao
Copy link
Contributor

Review status: 0 of 4 files reviewed, 2 unresolved discussions (waiting on @shenli, @lysu, @tiancaiamao, and @coocood)


server/column.go, line 50 at r3 (raw file):

How about change it like this:

if len(column.DefaultValue) == 0 {
    ...
} else {
    buffer = dumpUint64(buffer, 0)
}

Comments from Reviewable

@zz-jason zz-jason added the status/LGT1 Indicates that a PR has LGTM 1. label Jun 27, 2018
@tiancaiamao
Copy link
Contributor

Reviewed 1 of 4 files at r1, 2 of 3 files at r2, 1 of 1 files at r3.
Review status: all files reviewed, 2 unresolved discussions (waiting on @shenli, @lysu, and @coocood)


Comments from Reviewable

@shenli
Copy link
Member

shenli commented Jun 27, 2018

LGTM

@shenli
Copy link
Member

shenli commented Jun 27, 2018

/run-all-tests

@zz-jason
Copy link
Member

@tiancaiamao PTAL

1 similar comment
@lysu
Copy link
Contributor Author

lysu commented Jun 27, 2018

@tiancaiamao PTAL

@lysu
Copy link
Contributor Author

lysu commented Jun 27, 2018

/run-all-tests

@tiancaiamao
Copy link
Contributor

LGTM @shenli

@shenli
Copy link
Member

shenli commented Jun 27, 2018

LGTM

@shenli shenli added status/LGT2 Indicates that a PR has LGTM 2. and removed status/LGT1 Indicates that a PR has LGTM 1. labels Jun 27, 2018
shenli
shenli previously approved these changes Jun 27, 2018
@shenli
Copy link
Member

shenli commented Jun 27, 2018

@lysu Could you add some integration test for this?

@lysu
Copy link
Contributor Author

lysu commented Jun 28, 2018

/run-mybatis-test

lysu added 5 commits June 28, 2018 11:18
[column-definitions](https://dev.mysql.com/doc/internals/en/com-query-response.html#column-definition) in COM_FIELD_LIST response need write addition default-values part even though we omit default-values.
and some client like MariaDB-cli will read default-values length bit and meet fault if we haven't give it.
https://github.com/MariaDB/server/blob/72b6d01848e56a75349d663bc61bbe71f97a280b/sql-common/client.c#L1519

fix #6622
we should open for continue edition that fill default value.
@lysu
Copy link
Contributor Author

lysu commented Jun 28, 2018

PTAL @coocood

Copy link
Member

@zz-jason zz-jason left a comment

Choose a reason for hiding this comment

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

LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component/mysql-protocol status/LGT2 Indicates that a PR has LGTM 2.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

when loading data, execute “use database” crashed
5 participants