← Back to team overview

maria-developers team mailing list archive

Re: 55a4858fe6f: MDEV-12666: CURRENT_ROLE() does not work in a view

 

Hi, Vicentiu!

Another possible approach (that doesn't necessarily penalizes other
const functions that happen to return NULL) would be for
Item_func_sysconst not to behave as const during view creation. Because
they really aren't, sysconst functions can change between view
creation and a select from the view.

The fix would be, then

   Item *safe_charset_converter(THD *thd, CHARSET_INFO *tocs)
   {
+    if (thd->lex->context_analysis_only & CONTEXT_ANALYSIS_ONLY_VIEW)
+      return Item_str_func::safe_charset_converter(thd, tocs);
     return const_charset_converter(thd, tocs, true, fully_qualified_func_name()
   }

And possibly (not sure) other values of context_analysis_only would
need a similar treatment here.

On May 22, vicentiu wrote:
> revision-id: 55a4858fe6f3fdc63a072b93b9bc3d8e51dc5e94 (mariadb-10.0.30-76-g55a4858fe6f)
> parent(s): 8d1827f5540a0def82b1e2cbc557245c3e5e14ca
> author: Vicențiu Ciorbaru
> committer: Vicențiu Ciorbaru
> timestamp: 2017-05-22 17:06:01 +0300
> message:
> 
> MDEV-12666: CURRENT_ROLE() does not work in a view
> 
> The problem lies in how CURRENT_ROLE is defined. The
> Item_func_current_role inherits from Item_func_sysconst, which defines
> a safe_charset_converter to be a const_charset_converter.
> 
> During view creation, if there is no role previously set, the current_role()
> function returns NULL.
> 
> This is captured on item instantiation and the
> const_charset_converter call subsequently returns an Item_null.
> In turn, the function is replaced with Item_null and the view is
> then created with an Item_null instead of Item_func_current_role.
> 
> Without this patch, the first SHOW CREATE VIEW from the testcase would
> have a where clause of WHERE role_name = NULL, while the second SHOW
> CREATE VIEW would show a correctly created view.
> 
> The solution proposed is to not replace any function with an Item_null,
> but instead use an Item_static_string_func.
> 
Regards,
Sergei
Chief Architect MariaDB
and security@xxxxxxxxxxx