From 66c06735a2aeff32d69e5d2a4378563ad474691f Mon Sep 17 00:00:00 2001 From: Vladislav Vaintroub Date: Thu, 7 Jul 2022 15:14:14 +0200 Subject: MDEV-28746 Wrong error code ER_BAD_DB_ERROR for long filenames Add check for path length if CreateFile fails with ERROR_PATH_NOT_FOUND. --- mysys/my_winfile.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) (limited to 'mysys') diff --git a/mysys/my_winfile.c b/mysys/my_winfile.c index 0c76eb25560..0baca6d62d7 100644 --- a/mysys/my_winfile.c +++ b/mysys/my_winfile.c @@ -250,13 +250,12 @@ File my_win_sopen(const char *path, int oflag, int shflag, int pmode) if ((osfh= CreateFile(path, fileaccess, fileshare, &SecurityAttributes, filecreate, fileattrib, NULL)) == INVALID_HANDLE_VALUE) { - /* - OS call to open/create file failed! map the error, release - the lock, and return -1. note that it's not necessary to - call _free_osfhnd (it hasn't been used yet). - */ - my_osmaperr(GetLastError()); /* map error */ - DBUG_RETURN(-1); /* return error to caller */ + DWORD last_error= GetLastError(); + if (last_error == ERROR_PATH_NOT_FOUND && strlen(path) >= MAX_PATH) + errno= ENAMETOOLONG; + else + my_osmaperr(last_error); /* map error */ + DBUG_RETURN(-1); } if ((fh= my_open_osfhandle(osfh, -- cgit v1.2.1