diff options
author | unknown <iggy@recycle.(none)> | 2007-01-18 11:38:05 -0500 |
---|---|---|
committer | unknown <iggy@recycle.(none)> | 2007-01-18 11:38:05 -0500 |
commit | b1bfec73099b8349f07673e68d1d7ac25316dd4c (patch) | |
tree | 170d3d0ca24a93b60706c40ee189187211eb74f7 /client | |
parent | 74fa02e80cae99c6d6dc410f97f9a0e463dd1290 (diff) | |
download | mariadb-git-b1bfec73099b8349f07673e68d1d7ac25316dd4c.tar.gz |
Bug#22807 mysql_upgrade fails when called with a basedir-path containing spaces
- Create space safe strings for system() calls in mysql_upgrade.exe
client/mysql_upgrade.c:
Bug#22807 mysql_upgrade fails when called with a basedir-path containing spaces
- Make use of new dynstr_append_os_quoted function to produce a string safe for
passing to the system() function.
- Refactor possible source of assertion.
include/my_sys.h:
Bug#22807 mysql_upgrade fails when called with a basedir-path containing spaces
- Declare dynstr_append_os_quoted function.
mysys/string.c:
Bug#22807 mysql_upgrade fails when called with a basedir-path containing spaces
- Define dynstr_append_os_quoted function. This function will concatenate any
number of strings, escapes any OS quote in the result then surround the whole
affair in another set of quotes which is finally appended to specified
DYNAMIC_STRING.
Diffstat (limited to 'client')
-rw-r--r-- | client/mysql_upgrade.c | 77 |
1 files changed, 57 insertions, 20 deletions
diff --git a/client/mysql_upgrade.c b/client/mysql_upgrade.c index cce4b440be0..01e544af972 100644 --- a/client/mysql_upgrade.c +++ b/client/mysql_upgrade.c @@ -461,7 +461,12 @@ int main(int argc, char **argv) load_defaults("my", load_default_groups, &argc, &argv); - if (handle_options(&argc, &argv, my_long_options, get_one_option)) + /* + Must init_dynamic_string before handle_options because string is freed + at error label. + */ + if (init_dynamic_string(&cmdline, NULL, 2 * FN_REFLEN + 128, FN_REFLEN) || + handle_options(&argc, &argv, my_long_options, get_one_option)) { ret= 1; goto error; @@ -469,11 +474,6 @@ int main(int argc, char **argv) if (tty_password) opt_password= get_tty_password(NullS); - if (init_dynamic_string(&cmdline, NULL, 2 * FN_REFLEN + 128, FN_REFLEN)) - { - ret= 1; - goto error; - } if (!basedir) { my_getwd(path, sizeof(path), MYF(0)); @@ -556,17 +556,34 @@ int main(int argc, char **argv) goto error; } else - dynstr_set(&cmdline, path); + { +#ifdef __WIN__ + /* Windows requires an extra pair of quotes around the entire string. */ + dynstr_set(&cmdline, "\""); +#else + dynstr_set(&cmdline, ""); +#endif /* __WIN__ */ + dynstr_append_os_quoted(&cmdline, path, NullS); + } if (defaults_to_use) { - dynstr_append(&cmdline, " --defaults-extra-file="); - dynstr_append(&cmdline, defaults_to_use); + dynstr_append(&cmdline, " "); + dynstr_append_os_quoted(&cmdline, "--defaults-extra-file=", + defaults_to_use, NullS); } - - dynstr_append(&cmdline, " --check-upgrade --all-databases" - " --auto-repair --user="); - dynstr_append(&cmdline, user); + + dynstr_append(&cmdline, " "); + dynstr_append_os_quoted(&cmdline, "--check-upgrade", NullS); + dynstr_append(&cmdline, " "); + dynstr_append_os_quoted(&cmdline, "--all-databases", NullS); + dynstr_append(&cmdline, " "); + dynstr_append_os_quoted(&cmdline, "--auto-repair", NullS); + dynstr_append(&cmdline, " "); + dynstr_append_os_quoted(&cmdline, "--user=", user, NullS); +#ifdef __WIN__ + dynstr_append(&cmdline, "\""); +#endif /* __WIN__ */ if (opt_verbose) printf("Running %s\n", cmdline.str); @@ -595,7 +612,15 @@ fix_priv_tables: goto error; } else - dynstr_set(&cmdline, path); + { +#ifdef __WIN__ + /* Windows requires an extra pair of quotes around the entire string. */ + dynstr_set(&cmdline, "\""); +#else + dynstr_set(&cmdline, ""); +#endif /* __WIN__ */ + dynstr_append_os_quoted(&cmdline, path, NullS); + } if (find_file(MYSQL_FIX_PRIV_TABLES_NAME, basedir, MYF(0), path, sizeof(path), @@ -617,13 +642,25 @@ fix_priv_tables: if (defaults_to_use) { - dynstr_append(&cmdline, " --defaults-extra-file="); - dynstr_append(&cmdline, defaults_to_use); + dynstr_append(&cmdline, " "); + dynstr_append_os_quoted(&cmdline, "--defaults-extra-file=", + defaults_to_use, NullS); } - dynstr_append(&cmdline, " --force --no-auto-rehash --batch --user="); - dynstr_append(&cmdline, user); - dynstr_append(&cmdline, " mysql < "); - dynstr_append(&cmdline, script_line); + dynstr_append(&cmdline, " "); + dynstr_append_os_quoted(&cmdline, "--force", NullS); + dynstr_append(&cmdline, " "); + dynstr_append_os_quoted(&cmdline, "--no-auto-rehash", NullS); + dynstr_append(&cmdline, " "); + dynstr_append_os_quoted(&cmdline, "--batch", NullS); + dynstr_append(&cmdline, " "); + dynstr_append_os_quoted(&cmdline, "--user=", user, NullS); + dynstr_append(&cmdline, " "); + dynstr_append_os_quoted(&cmdline, "--database=mysql", NullS); + dynstr_append(&cmdline, " < "); + dynstr_append_os_quoted(&cmdline, script_line, NullS); +#ifdef __WIN__ + dynstr_append(&cmdline, "\""); +#endif /* __WIN__ */ if (opt_verbose) printf("Running %s\n", cmdline.str); |