Skip to content

Commit 0dd758e

Browse files
grooverdanspetrunia
authored andcommitted
MDEV-36765, followup 1: acl: handle json_unescape errors without crashing
json_unescape can return negative numbers, and with so we should free the buffer allocated. Also handle the NULL value in unsafe_str by not de-referencing NULL.
1 parent 39bb34b commit 0dd758e

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

sql/sql_acl.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1665,7 +1665,7 @@ class User_table_json: public User_table
16651665
set_int_value("version_id", (longlong) MYSQL_VERSION_ID);
16661666
}
16671667
const char *unsafe_str(const char *s) const
1668-
{ return s[0] ? s : NULL; }
1668+
{ return s ? (s[0] ? s : NULL) : NULL; }
16691669

16701670
SSL_type get_ssl_type () const override
16711671
{ return (SSL_type)get_int_value("ssl_type"); }
@@ -1764,6 +1764,8 @@ class User_table_json: public User_table
17641764
if (get_value(key, JSV_STRING, &value_start, &value_len))
17651765
return "";
17661766
char *ptr= (char*)alloca(value_len);
1767+
if (!ptr)
1768+
return NULL;
17671769
int len= json_unescape(m_table->field[2]->charset(),
17681770
(const uchar*)value_start,
17691771
(const uchar*)value_start + value_len,

0 commit comments

Comments
 (0)