diff options
author | unknown <marko@hundin.mysql.fi> | 2004-06-01 15:19:09 +0300 |
---|---|---|
committer | unknown <marko@hundin.mysql.fi> | 2004-06-01 15:19:09 +0300 |
commit | bab2231f7112e9808a1429c1409cc610131323b5 (patch) | |
tree | edf5227b878c8f401692637cae7a135939fcde65 /innobase/os | |
parent | c0b6c9f7e9067d01d1a57e21e560033b6a489ba0 (diff) | |
download | mariadb-git-bab2231f7112e9808a1429c1409cc610131323b5.tar.gz |
InnoDB cleanup: Fix potential buffer overflows,
allow deletion of tablespaces whose names contain "'"
innobase/dict/dict0load.c:
dict_check_tablespaces_or_store_max_id():
Dynamically allocate memory for file name
innobase/fil/fil0fil.c:
Dynamically allocate memory for file names
innobase/os/os0file.c:
os_file_dirname(): allocate slightly less memory
os_file_create_subdirs_if_needed(): compare more efficiently
innobase/row/row0mysql.c:
Allow tablespaces with "'" in their names to be deleted
Display identifiers with ut_print_name() or dict_index_name_print()
Diffstat (limited to 'innobase/os')
-rw-r--r-- | innobase/os/os0file.c | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/innobase/os/os0file.c b/innobase/os/os0file.c index a27da6d870e..caf09ed9f5f 100644 --- a/innobase/os/os0file.c +++ b/innobase/os/os0file.c @@ -2331,31 +2331,22 @@ os_file_dirname( pathname */ const char* path) /* in: pathname */ { - char* dir; - int i, length, last_slash; - /* find the offset of the last slash */ - length = ut_strlen(path); - for (i = length - 1; i >= 0 && path[i] != OS_FILE_PATH_SEPARATOR; i++); - last_slash = i; - - if (last_slash < 0) { + const char* last_slash = strrchr(path, OS_FILE_PATH_SEPARATOR); + if (!last_slash) { /* no slash in the path, return "." */ return(mem_strdup(".")); } /* ok, there is a slash */ - if (last_slash == 0) { + if (last_slash == path) { /* last slash is the first char of the path */ return(mem_strdup("/")); } /* non-trivial directory component */ - dir = mem_strdup(path); - dir[last_slash] = 0; - - return(dir); + return(mem_strdupl(path, last_slash - path)); } /******************************************************************** @@ -2369,12 +2360,12 @@ os_file_create_subdirs_if_needed( const char* path) /* in: path name */ { char* subdir; - static char rootdir[2] = { OS_FILE_PATH_SEPARATOR, 0 }; ibool success, subdir_exists; os_file_type_t type; subdir = os_file_dirname(path); - if (0 == strcmp(subdir, rootdir) || 0 == strcmp(subdir, ".")) { + if (strlen(subdir) == 1 + && (*subdir == OS_FILE_PATH_SEPARATOR || *subdir == '.')) { /* subdir is root or cwd, nothing to do */ ut_free(subdir); return(TRUE); |