summaryrefslogtreecommitdiff
path: root/mysys
diff options
context:
space:
mode:
authortomas@poseidon.ndb.mysql.com <>2005-05-31 14:37:47 +0200
committertomas@poseidon.ndb.mysql.com <>2005-05-31 14:37:47 +0200
commit5088b28d0958e0ece39a10dd1f242970bafd9575 (patch)
tree7c45fd5243b3cfbcdac69f6a06c9b1ae00ddc11e /mysys
parent30def9f3f878111eb504d77b54d287deb698e452 (diff)
parentea5c256b2701c38e151447dd9aa2fcff3070edff (diff)
downloadmariadb-git-5088b28d0958e0ece39a10dd1f242970bafd9575.tar.gz
Merge
Diffstat (limited to 'mysys')
-rw-r--r--mysys/default_modify.c2
-rw-r--r--mysys/my_access.c120
-rw-r--r--mysys/my_fopen.c22
-rw-r--r--mysys/my_getwd.c5
-rw-r--r--mysys/my_open.c10
-rw-r--r--mysys/raid.cc2
6 files changed, 129 insertions, 32 deletions
diff --git a/mysys/default_modify.c b/mysys/default_modify.c
index 3476b8628cf..add4317bb56 100644
--- a/mysys/default_modify.c
+++ b/mysys/default_modify.c
@@ -42,7 +42,7 @@ int modify_defaults_file(const char *file_location, const char *option,
const char *section_name, int remove_option)
{
FILE *cnf_file;
- struct stat file_stat;
+ MY_STAT file_stat;
char linebuff[BUFF_SIZE], tmp[BUFF_SIZE], *tmp_ptr, *src_ptr, *dst_ptr,
*file_buffer;
uint optlen, optval_len, sect_len;
diff --git a/mysys/my_access.c b/mysys/my_access.c
index 6a8887e42a6..28210bdfc7d 100644
--- a/mysys/my_access.c
+++ b/mysys/my_access.c
@@ -15,39 +15,107 @@
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
#include "mysys_priv.h"
+#include <m_string.h>
#ifdef __WIN__
/*
- * Check a file or path for accessability.
- *
- * SYNOPSIS
- * file_access()
- * pathpath to check
- * amodemode to check
- *
- * DESCRIPTION
- * This function wraps the normal access method because the access
- * available in MSVCRT> +reports that filenames such as LPT1 and
- * COM1 are valid (they are but should not be so for us).
- *
- * RETURN VALUES
- * 0 ok
- * -1 error
- */
+ Check a file or path for accessability.
+
+ SYNOPSIS
+ file_access()
+ path Path to file
+ amode Access method
+
+ DESCRIPTION
+ This function wraps the normal access method because the access
+ available in MSVCRT> +reports that filenames such as LPT1 and
+ COM1 are valid (they are but should not be so for us).
+
+ RETURN VALUES
+ 0 ok
+ -1 error (We use -1 as my_access is mapped to access on other platforms)
+*/
+
int my_access(const char *path, int amode)
{
- WIN32_FILE_ATTRIBUTE_DATA fileinfo;
- BOOL result;
+ WIN32_FILE_ATTRIBUTE_DATA fileinfo;
+ BOOL result;
- result = GetFileAttributesEx(path, GetFileExInfoStandard,
- &fileinfo);
- if (! result)
- return -1;
- if ((fileinfo.dwFileAttributes & FILE_ATTRIBUTE_READONLY) &&
- (amode & 2))
- return -1;
- return 0;
+ result= GetFileAttributesEx(path, GetFileExInfoStandard, &fileinfo);
+ if (! result ||
+ (fileinfo.dwFileAttributes & FILE_ATTRIBUTE_READONLY) && (amode & W_OK))
+ {
+ my_errno= errno= EACCES;
+ return -1;
+ }
+ return 0;
}
+#endif /* __WIN__ */
+
+#if defined(MSDOS) || defined(__WIN__) || defined(__EMX__)
+
+/*
+ List of file names that causes problem on windows
+
+ NOTE that one can also not have file names of type CON.TXT
+*/
+
+static const char *reserved_names[]=
+{
+ "CON", "PRN", "AUX", "NUL", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6",
+ "COM7", "COM8", "COM9", "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6",
+ "LPT7", "LPT8", "LPT9", "CLOCK$",
+ NullS
+};
+
+#define MAX_RESERVED_NAME_LENGTH 6
+
+/*
+ Check if a path will access a reserverd file name that may cause problems
+
+ SYNOPSIS
+ check_if_legal_filename
+ path Path to file
+
+ RETURN
+ 0 ok
+ 1 reserved file name
+*/
+
+int check_if_legal_filename(const char *path)
+{
+ const char *end;
+ const char **reserved_name;
+ DBUG_ENTER("check_if_legal_filename");
+
+ path+= dirname_length(path); /* To start of filename */
+ if (!(end= strchr(path, FN_EXTCHAR)))
+ end= strend(path);
+ if (path == end || (uint) (path - end) > MAX_RESERVED_NAME_LENGTH)
+ DBUG_RETURN(0); /* Simplify inner loop */
+
+ for (reserved_name= reserved_names; *reserved_name; reserved_name++)
+ {
+ const char *name= path;
+ while (name != end)
+ {
+ if (my_toupper(&my_charset_latin1, *path) !=
+ my_toupper(&my_charset_latin1, *name))
+ break;
+ if (name++ == end)
+ DBUG_RETURN(1); /* Found wrong path */
+ }
+ }
+ DBUG_RETURN(0);
+}
#endif
+
+
+#ifdef OS2
+int check_if_legal_filename(const char *path)
+{
+ return 0;
+}
+#endif /* OS2 */
diff --git a/mysys/my_fopen.c b/mysys/my_fopen.c
index e918b7b0de2..3c6f1b15384 100644
--- a/mysys/my_fopen.c
+++ b/mysys/my_fopen.c
@@ -33,9 +33,25 @@ FILE *my_fopen(const char *FileName, int Flags, myf MyFlags)
DBUG_ENTER("my_fopen");
DBUG_PRINT("my",("Name: '%s' Flags: %d MyFlags: %d",
FileName, Flags, MyFlags));
-
- make_ftype(type,Flags);
- if ((fd = fopen(FileName, type)) != 0)
+ /*
+ if we are not creating, then we need to use my_access to make sure
+ the file exists since Windows doesn't handle files like "com1.sym"
+ very well
+ */
+#ifdef __WIN__
+ if (check_if_legal_filename(FileName))
+ {
+ errno= EACCES;
+ fd= 0;
+ }
+ else
+#endif
+ {
+ make_ftype(type,Flags);
+ fd = fopen(FileName, type);
+ }
+
+ if (fd != 0)
{
/*
The test works if MY_NFILE < 128. The problem is that fileno() is char
diff --git a/mysys/my_getwd.c b/mysys/my_getwd.c
index 89f949eca27..5663ceaa60e 100644
--- a/mysys/my_getwd.c
+++ b/mysys/my_getwd.c
@@ -208,7 +208,10 @@ int test_if_hard_path(register const char *dir_name)
my_bool has_path(const char *name)
{
- return test(strchr(name, FN_LIBCHAR))
+ return test(strchr(name, FN_LIBCHAR))
+#if FN_LIBCHAR != '/'
+ || test(strchr(name,'/'))
+#endif
#ifdef FN_DEVCHAR
|| test(strchr(name, FN_DEVCHAR))
#endif
diff --git a/mysys/my_open.c b/mysys/my_open.c
index a5cd3811bbf..69d63c49554 100644
--- a/mysys/my_open.c
+++ b/mysys/my_open.c
@@ -46,6 +46,16 @@ File my_open(const char *FileName, int Flags, myf MyFlags)
DBUG_PRINT("my",("Name: '%s' Flags: %d MyFlags: %d",
FileName, Flags, MyFlags));
#if defined(MSDOS) || defined(__WIN__) || defined(__EMX__) || defined(OS2)
+ /*
+ Check that we don't try to open or create a file name that may
+ cause problems for us in the future (like PRN)
+ */
+ if (check_if_legal_filename(FileName))
+ {
+ errno= EACCES;
+ DBUG_RETURN(my_register_filename(-1, FileName, FILE_BY_OPEN,
+ EE_FILENOTFOUND, MyFlags));
+ }
if (Flags & O_SHARE)
fd = sopen((my_string) FileName, (Flags & ~O_SHARE) | O_BINARY, SH_DENYNO,
MY_S_IREAD | MY_S_IWRITE);
diff --git a/mysys/raid.cc b/mysys/raid.cc
index 1d2e0cb01f0..29819a878c4 100644
--- a/mysys/raid.cc
+++ b/mysys/raid.cc
@@ -70,7 +70,7 @@
tonu@mysql.com & monty@mysql.com
*/
-#ifdef __GNUC__
+#ifdef USE_PRAGMA_IMPLEMENTATION
#pragma implementation // gcc: Class implementation
#endif