[MDEV-28746] Wrong error code ER_BAD_DB_ERROR for long filenames Created: 2022-06-03  Updated: 2022-07-07  Resolved: 2022-07-07

Status: Closed
Project: MariaDB Server
Component/s: Platform Windows
Affects Version/s: 10.7
Fix Version/s: 10.3.36, 10.4.26, 10.5.17, 10.6.9, 10.7.5, 10.8.4

Type: Bug Priority: Major
Reporter: Aleksey Midenkov Assignee: Vladislav Vaintroub
Resolution: Fixed Votes: 0
Labels: None


 Description   

Tested on 10.7, probably affects lower versions.

Reproduce

set names utf8;
let $save_debug=`select @@debug_dbug`;
let $MYSQLD_DATADIR= `SELECT @@datadir`;
# Filename is too long because it is converted to @274e@274e@274e@274e...
# so each '❎' is 5 bytes in filesystem, 51 x 5 = 255 bytes
let $t= `select repeat('❎', 51)`;
--error ER_CANT_CREATE_TABLE
eval create table $t (x int);

Result

ER_BAD_DB_ERROR is thrown, misguiding error message Unknown database 'test'

mysqltest: At line 7: query 'create table $t (x int)' failed: ER_BAD_DB_ERROR (1049): Unknown database 'test'

Expected

ER_CANT_CREATE_TABLE is thrown on Linux

ERROR HY000: Can't create table `test`.`❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎❎ ❎❎❎❎❎❎❎❎❎❎❎❎❎` (errno: 36 "File name too long")

Notes

The fork for different error codes is here:

int writefile(const char *path, const char *db, const char *table,
              bool tmp_table, const uchar *data, size_t len)
{
...
  File file= mysql_file_create(key_file_frm, path,
                               CREATE_MODE, create_flags, MYF(0));
 
  if (unlikely((error= file < 0)))
  {
    if (my_errno == ENOENT)
      my_error(ER_BAD_DB_ERROR, MYF(0), db);
    else
      my_error(ER_CANT_CREATE_TABLE, MYF(0), db, table, my_errno);
  }
...

On Windows it sets my_errno to ENOENT, on Linux it sets my_errno to 36 ("File name too long").


Generated at Thu Feb 08 10:03:09 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.