Login
[x]
Log in using an account from:
Fedora Account System
Red Hat Associate
Red Hat Customer
Or login using a Red Hat Bugzilla account
Forgot Password
Login:
Hide Forgot
Create an Account
Red Hat Bugzilla – Attachment 316912 Details for
Bug 462534
SQL Config files should not be read more than once
[?]
New
Simple Search
Advanced Search
My Links
Browse
Requests
Reports
Current State
Search
Tabular reports
Graphical reports
Duplicates
Other Reports
User Changes
Plotly Reports
Bug Status
Bug Severity
Non-Defaults
|
Product Dashboard
Help
Page Help!
Bug Writing Guidelines
What's new
Browser Support Policy
5.0.4.rh83 Release notes
FAQ
Guides index
User guide
Web Services
Contact
Legal
This site requires JavaScript to be enabled to function correctly, please enable it.
[patch]
Proposed patch
mysql-read-config-files-once.patch (text/plain), 17.38 KB, created by
Bryan Mason
on 2008-09-16 22:27:29 UTC
(
hide
)
Description:
Proposed patch
Filename:
MIME Type:
Creator:
Bryan Mason
Created:
2008-09-16 22:27:29 UTC
Size:
17.38 KB
patch
obsolete
>diff --exclude='*~' -Naur mysql-5.0.45.orig/include/my_sys.h mysql-5.0.45.new/include/my_sys.h >--- mysql-5.0.45.orig/include/my_sys.h 2007-07-04 06:06:39.000000000 -0700 >+++ mysql-5.0.45.new/include/my_sys.h 2008-09-15 16:25:59.421576000 -0700 >@@ -675,6 +675,7 @@ > const char *form, uint flag); > extern size_s strlength(const char *str); > extern void pack_dirname(my_string to,const char *from); >+extern uint normalize_dirname(char * to, const char *from); > extern uint unpack_dirname(my_string to,const char *from); > extern uint cleanup_dirname(my_string to,const char *from); > extern uint system_filename(my_string to,const char *from); >@@ -691,6 +692,8 @@ > extern int wf_test(struct wild_file_pack *wf_pack,const char *name); > extern void wf_end(struct wild_file_pack *buffer); > extern size_s strip_sp(my_string str); >+extern my_bool array_append_string_unique(const char *str, >+ const char **array, size_t size); > extern void get_date(my_string to,int timeflag,time_t use_time); > extern void soundex(CHARSET_INFO *, my_string out_pntr, my_string in_pntr,pbool remove_garbage); > extern int init_record_cache(RECORD_CACHE *info,uint cachesize,File file, >diff --exclude='*~' -Naur mysql-5.0.45.orig/libmysql/CMakeLists.txt mysql-5.0.45.new/libmysql/CMakeLists.txt >--- mysql-5.0.45.orig/libmysql/CMakeLists.txt 2007-07-04 06:06:49.000000000 -0700 >+++ mysql-5.0.45.new/libmysql/CMakeLists.txt 2008-09-15 16:53:41.669936000 -0700 >@@ -44,7 +44,7 @@ > ../mysys/default.c ../libmysql/errmsg.c ../mysys/errors.c > ../libmysql/get_password.c ../strings/int2str.c ../strings/is_prefix.c > ../libmysql/libmysql.c ../mysys/list.c ../strings/llstr.c >- ../strings/longlong2str.c ../libmysql/manager.c ../mysys/mf_cache.c >+ ../strings/longlong2str.c ../libmysql/manager.c ../mysys/mf_arr_appstr.c ../mysys/mf_cache.c > ../mysys/mf_dirname.c ../mysys/mf_fn_ext.c ../mysys/mf_format.c > ../mysys/mf_iocache.c ../mysys/mf_iocache2.c ../mysys/mf_loadpath.c > ../mysys/mf_pack.c ../mysys/mf_path.c ../mysys/mf_tempfile.c ../mysys/mf_unixpath.c >diff --exclude='*~' -Naur mysql-5.0.45.orig/libmysql/Makefile.shared mysql-5.0.45.new/libmysql/Makefile.shared >--- mysql-5.0.45.orig/libmysql/Makefile.shared 2007-07-04 06:06:10.000000000 -0700 >+++ mysql-5.0.45.new/libmysql/Makefile.shared 2008-09-16 10:37:11.042748000 -0700 >@@ -59,7 +59,7 @@ > mf_pack.lo my_messnc.lo mf_dirname.lo mf_fn_ext.lo\ > mf_wcomp.lo typelib.lo safemalloc.lo my_alloc.lo \ > mf_format.lo mf_path.lo mf_unixpath.lo my_fopen.lo \ >- my_symlink.lo my_fstream.lo \ >+ my_symlink.lo my_fstream.lo mf_arr_appstr.lo \ > mf_loadpath.lo my_pthread.lo my_thr_init.lo \ > thr_mutex.lo mulalloc.lo string.lo \ > default.lo default_modify.lo \ >diff --exclude='*~' -Naur mysql-5.0.45.orig/mysys/CMakeLists.txt mysql-5.0.45.new/mysys/CMakeLists.txt >--- mysql-5.0.45.orig/mysys/CMakeLists.txt 2007-07-04 06:06:25.000000000 -0700 >+++ mysql-5.0.45.new/mysys/CMakeLists.txt 2008-09-15 16:48:04.841280000 -0700 >@@ -31,7 +31,7 @@ > errors.c hash.c list.c md5.c mf_brkhant.c mf_cache.c mf_dirname.c mf_fn_ext.c > mf_format.c mf_getdate.c mf_iocache.c mf_iocache2.c mf_keycache.c > mf_keycaches.c mf_loadpath.c mf_pack.c mf_path.c mf_qsort.c mf_qsort2.c >- mf_radix.c mf_same.c mf_sort.c mf_soundex.c mf_strip.c mf_tempdir.c >+ mf_radix.c mf_same.c mf_sort.c mf_soundex.c mf_strip.c mf_arr_appstr.c mf_tempdir.c > mf_tempfile.c mf_unixpath.c mf_wcomp.c mf_wfile.c mulalloc.c my_access.c > my_aes.c my_alarm.c my_alloc.c my_append.c my_bit.c my_bitmap.c my_chsize.c > my_clock.c my_compress.c my_conio.c my_copy.c my_crc32.c my_create.c my_delete.c >diff --exclude='*~' -Naur mysql-5.0.45.orig/mysys/default.c mysql-5.0.45.new/mysys/default.c >--- mysql-5.0.45.orig/mysys/default.c 2007-07-04 06:06:27.000000000 -0700 >+++ mysql-5.0.45.new/mysys/default.c 2008-09-15 12:42:38.384960000 -0700 >@@ -48,13 +48,13 @@ > /* Which directories are searched for options (and in which order) */ > > #define MAX_DEFAULT_DIRS 7 >-const char *default_directories[MAX_DEFAULT_DIRS + 1]; >+#define DEFAULT_DIRS_SIZE (MAX_DEFAULT_DIRS + 1) /* Terminate with NULL */ >+static const char **default_directories = NULL; >+ > > #ifdef __WIN__ > static const char *f_extensions[]= { ".ini", ".cnf", 0 }; > #define NEWLINE "\r\n" >-static char system_dir[FN_REFLEN], shared_system_dir[FN_REFLEN], >- config_dir[FN_REFLEN]; > #else > static const char *f_extensions[]= { ".cnf", 0 }; > #define NEWLINE "\n" >@@ -83,7 +83,37 @@ > void *func_ctx, > const char *dir, const char *ext, > const char *config_file, int recursion_level); >-static void init_default_directories(); >+ >+ >+/** >+ Create the list of default directories. >+ >+ @param alloc MEM_ROOT where the list of directories is stored >+ >+ @details >+ The directories searched, in order, are: >+ - Windows: GetSystemWindowsDirectory() >+ - Windows: GetWindowsDirectory() >+ - Windows: C:/ >+ - Windows: Directory above where the executable is located >+ - Netware: sys:/etc/ >+ - Unix & OS/2: /etc/ >+ - Unix: --sysconfdir=<path> (compile-time option) >+ - OS/2: getenv(ETC) >+ - ALL: getenv(DEFAULT_HOME_ENV) >+ - ALL: --defaults-extra-file=<path> (run-time option) >+ - Unix: ~/ >+ >+ On all systems, if a directory is already in the list, it will be moved >+ to the end of the list. This avoids reading defaults files multiple times, >+ while ensuring the correct precedence. >+ >+ @retval NULL Failure (out of memory, probably) >+ @retval other Pointer to NULL-terminated array of default directories >+*/ >+ >+static const char **init_default_directories(MEM_ROOT *alloc); >+ > > static char *remove_end_comment(char *ptr); > >@@ -371,8 +401,9 @@ > struct handle_option_ctx ctx; > DBUG_ENTER("load_defaults"); > >- init_default_directories(); > init_alloc_root(&alloc,512,0); >+ if ((default_directories= init_default_directories(&alloc)) == NULL) >+ goto err; > /* > Check if the user doesn't want any default option processing > --no-defaults is always the first option >@@ -849,34 +880,49 @@ > my_bool have_ext= fn_ext(conf_file)[0] != 0; > const char **exts_to_use= have_ext ? empty_list : f_extensions; > char name[FN_REFLEN], **ext; >- const char **dirs; > >- init_default_directories(); > puts("\nDefault options are read from the following files in the given order:"); > > if (dirname_length(conf_file)) > fputs(conf_file,stdout); > else > { >- for (dirs=default_directories ; *dirs; dirs++) >+ /* >+ If default_directories is already initialized, use it. Otherwise, >+ use a private MEM_ROOT. >+ */ >+ const char **dirs = default_directories; >+ MEM_ROOT alloc; >+ init_alloc_root(&alloc,512,0); >+ >+ if (!dirs && (dirs= init_default_directories(&alloc)) == NULL) > { >- for (ext= (char**) exts_to_use; *ext; ext++) >+ fputs("Internal error initializing default directories list", stdout); >+ } >+ else >+ { >+ for ( ; *dirs; dirs++) > { >- const char *pos; >- char *end; >- if (**dirs) >- pos= *dirs; >- else if (my_defaults_extra_file) >- pos= my_defaults_extra_file; >- else >- continue; >- end= convert_dirname(name, pos, NullS); >- if (name[0] == FN_HOMELIB) /* Add . to filenames in home */ >- *end++='.'; >- strxmov(end, conf_file, *ext, " ", NullS); >- fputs(name,stdout); >+ for (ext= (char**) exts_to_use; *ext; ext++) >+ { >+ const char *pos; >+ char *end; >+ if (**dirs) >+ pos= *dirs; >+ else if (my_defaults_extra_file) >+ pos= my_defaults_extra_file; >+ else >+ continue; >+ end= convert_dirname(name, pos, NullS); >+ if (name[0] == FN_HOMELIB) /* Add . to filenames in home */ >+ *end++= '.'; >+ strxmov(end, conf_file, *ext, " ", NullS); >+ fputs(name, stdout); >+ } > } > } >+ >+ free_root(&alloc, MYF(0)); > } > puts(""); > } >@@ -913,6 +959,24 @@ > #include <help_end.h> > > >+static int add_directory(MEM_ROOT *alloc, const char *dir, const char **dirs) >+{ >+ char buf[FN_REFLEN]; >+ uint len; >+ char *p; >+ my_bool err __attribute__((unused)); >+ >+ len= normalize_dirname(buf, dir); >+ if (!(p= strmake_root(alloc, buf, len))) >+ return 1; /* Failure */ >+ /* Should never fail if DEFAULT_DIRS_SIZE is correct size */ >+ err= array_append_string_unique(p, dirs, DEFAULT_DIRS_SIZE); >+ DBUG_ASSERT(err == FALSE); >+ >+ return 0; >+} >+ >+ > #ifdef __WIN__ > /* > This wrapper for GetSystemWindowsDirectory() will dynamically bind to the >@@ -947,108 +1011,95 @@ > } > return count; > } >-#endif > > >-/* >- Create the list of default directories. >+static const char *my_get_module_parent(char *buf, size_t size) >+{ >+ char *last= NULL; >+ char *end; >+ if (!GetModuleFileName(NULL, buf, (DWORD) size)) >+ return NULL; >+ end= strend(buf); >+ >+ /* >+ Look for the second-to-last \ in the filename, but hang on >+ to a pointer after the last \ in case we're in the root of >+ a drive. >+ */ >+ for ( ; end > buf; end--) >+ { >+ if (*end == FN_LIBCHAR) >+ { >+ if (last) >+ { >+ /* Keep the last '\' as this works both with D:\ and a directory */ >+ end[1]= 0; >+ break; >+ } >+ last= end; >+ } >+ } > >- On Microsoft Windows, this is: >- 1. C:/ >- 2. GetWindowsDirectory() >- 3. GetSystemWindowsDirectory() >- 4. getenv(DEFAULT_HOME_ENV) >- 5. Directory above where the executable is located >- 6. "" >- 7. --sysconfdir=<path> >- >- On Novell NetWare, this is: >- 1. sys:/etc/ >- 2. getenv(DEFAULT_HOME_ENV) >- 3. "" >- 4. --sysconfdir=<path> >- >- On OS/2, this is: >- 1. getenv(ETC) >- 2. /etc/ >- 3. getenv(DEFAULT_HOME_ENV) >- 4. "" >- 5. "~/" >- 6. --sysconfdir=<path> >- >- Everywhere else, this is: >- 1. /etc/ >- 2. getenv(DEFAULT_HOME_ENV) >- 3. "" >- 4. "~/" >- 5. --sysconfdir=<path> >+ return buf; >+} >+#endif /* __WIN__ */ > >- */ > >-static void init_default_directories() >+static const char **init_default_directories(MEM_ROOT *alloc) > { >- const char *env, **ptr= default_directories; >+ const char **dirs; >+ char *env; >+ int errors= 0; >+ >+ dirs= (const char **)alloc_root(alloc, DEFAULT_DIRS_SIZE * sizeof(char *)); >+ if (dirs == NULL) >+ return NULL; >+ bzero((char *) dirs, DEFAULT_DIRS_SIZE * sizeof(char *)); > > #ifdef __WIN__ >- *ptr++= "C:/"; > >- if (GetWindowsDirectory(system_dir,sizeof(system_dir))) >- *ptr++= (char*)&system_dir; >- if (my_get_system_windows_directory(shared_system_dir, >- sizeof(shared_system_dir)) && >- strcmp(system_dir, shared_system_dir)) >- *ptr++= (char *)&shared_system_dir; >+ { >+ char fname_buffer[FN_REFLEN]; >+ if (my_get_system_windows_directory(fname_buffer, sizeof(fname_buffer))) >+ errors += add_directory(alloc, fname_buffer, dirs); >+ >+ if (GetWindowsDirectory(fname_buffer, sizeof(fname_buffer))) >+ errors += add_directory(alloc, fname_buffer, dirs); >+ >+ errors += add_directory(alloc, "C:/", dirs); >+ >+ if (my_get_module_parent(fname_buffer, sizeof(fname_buffer)) != NULL) >+ errors += add_directory(alloc, fname_buffer, dirs); >+ } > > #elif defined(__NETWARE__) >- *ptr++= "sys:/etc/"; >+ >+ errors += add_directory(alloc, "sys:/etc/", dirs); >+ > #else >+ >+ errors += add_directory(alloc, "/etc/", dirs); >+ > #if defined(__EMX__) || defined(OS2) > if ((env= getenv("ETC"))) >- *ptr++= env; >-#endif >- *ptr++= "/etc/"; >+ errors += add_directory(alloc, env, dirs); >+#elif defined(DEFAULT_SYSCONFDIR) >+ if (DEFAULT_SYSCONFDIR != "") >+ errors += add_directory(alloc, DEFAULT_SYSCONFDIR, dirs); >+#endif /* __EMX__ || __OS2__ */ >+ > #endif >+ > if ((env= getenv(STRINGIFY_ARG(DEFAULT_HOME_ENV)))) >- *ptr++= env; >- *ptr++= ""; /* Place for defaults_extra_file */ >-#if !defined(__WIN__) && !defined(__NETWARE__) >- *ptr++= "~/";; >-#elif defined(__WIN__) >- if (GetModuleFileName(NULL, config_dir, sizeof(config_dir))) >- { >- char *last= NULL, *end= strend(config_dir); >- /* >- Look for the second-to-last \ in the filename, but hang on >- to a pointer after the last \ in case we're in the root of >- a drive. >- */ >- for ( ; end > config_dir; end--) >- { >- if (*end == FN_LIBCHAR) >- { >- if (last) >- { >- if (end != config_dir) >- { >- /* Keep the last '\' as this works both with D:\ and a directory */ >- end[1]= 0; >- } >- else >- { >- /* No parent directory (strange). Use current dir + '\' */ >- last[1]= 0; >- } >- break; >- } >- last= end; >- } >- } >- *ptr++= (char *)&config_dir; >- } >-#endif >-#ifdef DEFAULT_SYSCONFDIR >- if (DEFAULT_SYSCONFDIR != "") >- *ptr++= DEFAULT_SYSCONFDIR; >+ errors += add_directory(alloc, env, dirs); >+ >+ /* Placeholder for --defaults-extra-file=<path> */ >+ errors += add_directory(alloc, "", dirs); >+ >+#if !defined(__WIN__) && !defined(__NETWARE__) && \ >+ !defined(__EMX__) && !defined(OS2) >+ errors += add_directory(alloc, "~/", dirs); > #endif >- *ptr= 0; /* end marker */ >+ >+ return (errors > 0 ? NULL : dirs); > } >diff --exclude='*~' -Naur mysql-5.0.45.orig/mysys/Makefile.am mysql-5.0.45.new/mysys/Makefile.am >--- mysql-5.0.45.orig/mysys/Makefile.am 2007-07-04 06:06:25.000000000 -0700 >+++ mysql-5.0.45.new/mysys/Makefile.am 2008-09-15 17:03:45.190524000 -0700 >@@ -38,7 +38,7 @@ > my_error.c errors.c my_div.c my_messnc.c \ > mf_format.c mf_same.c mf_dirname.c mf_fn_ext.c \ > my_symlink.c my_symlink2.c \ >- mf_pack.c mf_unixpath.c mf_strip.c \ >+ mf_pack.c mf_unixpath.c mf_strip.c mf_arr_appstr.c \ > mf_wcomp.c mf_wfile.c my_gethwaddr.c \ > mf_qsort.c mf_qsort2.c mf_sort.c \ > ptr_cmp.c mf_radix.c queues.c \ >diff --exclude='*~' -Naur mysql-5.0.45.orig/mysys/mf_arr_appstr.c mysql-5.0.45.new/mysys/mf_arr_appstr.c >--- mysql-5.0.45.orig/mysys/mf_arr_appstr.c 1969-12-31 16:00:00.000000000 -0800 >+++ mysql-5.0.45.new/mysys/mf_arr_appstr.c 2008-09-15 16:26:51.419368000 -0700 >@@ -0,0 +1,61 @@ >+/* Copyright (C) 2007 MySQL AB >+ >+ This program is free software; you can redistribute it and/or modify >+ it under the terms of the GNU General Public License as published by >+ the Free Software Foundation; version 2 of the License. >+ >+ This program is distributed in the hope that it will be useful, >+ but WITHOUT ANY WARRANTY; without even the implied warranty of >+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the >+ GNU General Public License for more details. >+ >+ You should have received a copy of the GNU General Public License >+ along with this program; if not, write to the Free Software >+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ >+ >+#include "mysys_priv.h" >+#include <m_string.h> /* strcmp() */ >+ >+ >+/** >+ Append str to array, or move to the end if it already exists >+ >+ @param str String to be appended >+ @param array The array, terminated by a NULL element, all unused elements >+ pre-initialized to NULL >+ @param size Size of the array; array must be terminated by a NULL >+ pointer, so can hold size - 1 elements >+ >+ @retval FALSE Success >+ @retval TRUE Failure, array is full >+*/ >+ >+my_bool array_append_string_unique(const char *str, >+ const char **array, size_t size) >+{ >+ const char **p; >+ /* end points at the terminating NULL element */ >+ const char **end= array + size - 1; >+ DBUG_ASSERT(*end == NULL); >+ >+ for (p= array; *p; ++p) >+ { >+ if (strcmp(*p, str) == 0) >+ break; >+ } >+ if (p >= end) >+ return TRUE; /* Array is full */ >+ >+ DBUG_ASSERT(*p == NULL || strcmp(*p, str) == 0); >+ >+ while (*(p + 1)) >+ { >+ *p= *(p + 1); >+ ++p; >+ } >+ >+ DBUG_ASSERT(p < end); >+ *p= str; >+ >+ return FALSE; /* Success */ >+} >diff --exclude='*~' -Naur mysql-5.0.45.orig/mysys/mf_pack.c mysql-5.0.45.new/mysys/mf_pack.c >--- mysql-5.0.45.orig/mysys/mf_pack.c 2007-07-04 06:06:59.000000000 -0700 >+++ mysql-5.0.45.new/mysys/mf_pack.c 2008-09-15 13:02:29.623200000 -0700 >@@ -266,6 +266,51 @@ > #endif /* USE_SYMDIR */ > > >+/** >+ Convert a directory name to a format which can be compared as strings >+ >+ @param to result buffer, FN_REFLEN chars in length; may be == from >+ @param from 'packed' directory name, in whatever format >+ @returns size of the normalized name >+ >+ @details >+ - Ensures that last char is FN_LIBCHAR, unless it is FN_DEVCHAR >+ - Uses cleanup_dirname >+ >+ It does *not* expand ~/ (although, see cleanup_dirname). Nor does it do >+ any case folding. All case-insensitive normalization should be done by >+ the caller. >+*/ >+ >+uint normalize_dirname(char *to, const char *from) >+{ >+ uint length; >+ char buff[FN_REFLEN]; >+ DBUG_ENTER("normalize_dirname"); >+ >+ /* >+ Despite the name, this actually converts the name to the system's >+ format (TODO: rip out the non-working VMS stuff and name this >+ properly). >+ */ >+ (void) intern_filename(buff, from); >+ length= (uint) strlen(buff); /* Fix that '/' is last */ >+ if (length && >+#ifdef FN_DEVCHAR >+ buff[length - 1] != FN_DEVCHAR && >+#endif >+ buff[length - 1] != FN_LIBCHAR && buff[length - 1] != '/') >+ { >+ buff[length]= FN_LIBCHAR; >+ buff[length + 1]= '\0'; >+ } >+ >+ length=cleanup_dirname(to, buff); >+ >+ DBUG_RETURN(length); >+} >+ >+ > /* > Fixes a directroy name so that can be used by open() >
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 462534
: 316912