We're updating the issue view to help you get more done.Learn more

Wrong implementation of checking PLUGIN_VAR_SET condition

This issue is MariaDB specific. MySQL is not implement this condition checking.

In sql_plugin.cc, MariaDB implements PLUGIN_VAR_STR check as follows:

1 2 3 4 3963 if (mysqld_server_started && 3964 ((o->flags & (PLUGIN_VAR_STR | PLUGIN_VAR_NOCMDOPT | 3965 PLUGIN_VAR_MEMALLOC)) == PLUGIN_VAR_STR)) 3966 {

But, this implementation has a critical bug which causes SEGV.

This SEGV issues causes as follows:

  • Build latest Mroonga

  • Install built Mroonga into MariaDB

  • MySQL client lost connection against mysqld.

1 2 MariaDB [(none)]> INSTALL PLUGIN Mroonga SONAME 'ha_mroonga.dll'; ERROR 2013 (HY000): Lost connection to MySQL server during query

Because, these phenomena causes wrong condition about PLUGIN_VAR_STR.

In include/mysql/plugin.h, a series of PLUGIN_* value defined.
But, these value has a misleading point.

Here is the misleading point:
From PLUGIN_VAR_BOOL to PLUGIN_VAR_DOUBLE are not assumed as a flag. But, defined after PLUGIN_VAR_UNSIGNED macro value are designed as a flag.

OK, let's apply above description in practice.

Here is the line which has causes problem:

1 (o->flags & (PLUGIN_VAR_STR | PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_MEMALLOC)) == PLUGIN_VAR_STR

From above description,

1 o->flags & (PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_MEMALLOC)

is valid, because PLUGIN_VAR_NOCMDOPT and PLUGIN_VAR_MEMALLOC are designed as a flag. It is valid.
But,

1 (o->flags & PLUGIN_VAR_STR) == PLUGIN_VAR_STR

is invalid code. Because,

1 (PLUGIN_VAR_SET & PLUGIN_VAR_STR) == PLUGIN_VAR_STR

is true!
In more detail, PLUGIN_VAR_STR and PLUGIN_VAR_SET are defined as follows in include/mysql/plugin.h:

1 2 #define PLUGIN_VAR_STR 0x0005 #define PLUGIN_VAR_SET 0x0007

So, PLUGIN_VAR_SET & PLUGIN_VAR_STR ( 0x0007 AND 0x0005) equals PLUGIN_VAR_STR (0x0005).

This result causes following bug:
In latest Mroonga, specifies PLUGIN_VAR_SET ( https://github.com/mroonga/mroonga/blob/master/ha_mroonga.cpp#L965 ), not specifies PLUGIN_VAR_STR. But,

1 (o->flags & (PLUGIN_VAR_STR | PLUGIN_VAR_NOCMDOPT | PLUGIN_VAR_MEMALLOC)) == PLUGIN_VAR_STR

matches PLUGIN_VAR_STR, in spite of PLUGIN_VAR_STR is not set (NULL).

As a result, causes SEGV and not to be able to register Mroonga storage engine plugin into MariaDB.

I've added a fix patch which is written by Kohei Sutou.
original patch found by (Sorry, this email is in Japanese...) : http://sourceforge.jp/projects/groonga/lists/archive/dev/2015-January/003067.html

Status

Assignee

Sergei Golubchik

Reporter

hiroshi HATAKE

Labels

Components

Fix versions

Affects versions

5.5.41
10.0.15

Priority

Major