From 324d8a6036baf6c2d15f6e7b898a60e3103f662a Mon Sep 17 00:00:00 2001 From: Vicentiu Ciorbaru Date: Mon, 5 Jun 2023 11:05:22 +0300 Subject: [PATCH] Fix segfault in find_files if db is NULL and path does not exist or can't be read In this case, one would end up calling my_error(ER_BAD_DB_ERROR, ...) with a null ptr for DB, which caused a NULL ptr dereference. --- sql/sql_show.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sql/sql_show.cc b/sql/sql_show.cc index c163d0d5fbe..d10cea97f2e 100644 --- a/sql/sql_show.cc +++ b/sql/sql_show.cc @@ -943,7 +943,7 @@ find_files(THD *thd, Dynamic_array *files, LEX_CSTRING *db, if (!(dirp = my_dir(path, MY_THREAD_SPECIFIC | (db ? 0 : MY_WANT_STAT)))) { - if (my_errno == ENOENT) + if (my_errno == ENOENT && db) my_error(ER_BAD_DB_ERROR, MYF(0), db->str); else my_error(ER_CANT_READ_DIR, MYF(0), path, my_errno);