Commit 79efd9db authored by unknown's avatar unknown

Fixed a bug in mysql client.


client/mysql.cc:
  Fixed a bug that caused segmentation fault in internal 'tee' command.
parent 95f2b1e6
...@@ -40,7 +40,7 @@ ...@@ -40,7 +40,7 @@
#include <signal.h> #include <signal.h>
#include <violite.h> #include <violite.h>
const char *VER= "12.8"; const char *VER= "12.9";
/* Don't try to make a nice table if the data is too big */ /* Don't try to make a nice table if the data is too big */
#define MAX_COLUMN_LENGTH 1024 #define MAX_COLUMN_LENGTH 1024
...@@ -617,13 +617,11 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), ...@@ -617,13 +617,11 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
{ {
if (opt_outfile) if (opt_outfile)
end_tee(); end_tee();
opt_outfile= 0;
} }
else else
if (!opt_outfile) if (!opt_outfile)
{ {
strmov(outfile, argument); strmov(outfile, argument);
opt_outfile= 1;
init_tee(); init_tee();
} }
break; break;
...@@ -631,7 +629,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), ...@@ -631,7 +629,6 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)),
printf("WARNING: option depricated; use --disable-tee instead.\n"); printf("WARNING: option depricated; use --disable-tee instead.\n");
if (opt_outfile) if (opt_outfile)
end_tee(); end_tee();
opt_outfile= 0;
break; break;
case OPT_PAGER: case OPT_PAGER:
opt_nopager= 0; opt_nopager= 0;
...@@ -1510,17 +1507,22 @@ static void end_pager() ...@@ -1510,17 +1507,22 @@ static void end_pager()
static void init_tee() static void init_tee()
{ {
if (opt_outfile)
end_tee();
if (!(OUTFILE= my_fopen(outfile, O_APPEND | O_WRONLY, MYF(MY_WME)))) if (!(OUTFILE= my_fopen(outfile, O_APPEND | O_WRONLY, MYF(MY_WME))))
{ {
opt_outfile=0; opt_outfile= 0;
init_pager(); init_pager();
return; return;
} }
opt_outfile= 1;
tee_fprintf(stdout, "Logging to file '%s'\n", outfile);
} }
static void end_tee() static void end_tee()
{ {
my_fclose(OUTFILE, MYF(0)); my_fclose(OUTFILE, MYF(0));
opt_outfile= 0;
return; return;
} }
...@@ -1807,7 +1809,7 @@ print_tab_data(MYSQL_RES *result) ...@@ -1807,7 +1809,7 @@ print_tab_data(MYSQL_RES *result)
for (uint off=1 ; off < mysql_num_fields(result); off++) for (uint off=1 ; off < mysql_num_fields(result); off++)
{ {
(void) tee_fputs("\t", PAGER); (void) tee_fputs("\t", PAGER);
safe_put_field(cur[off],lengths[off]); safe_put_field(cur[off], lengths[off]);
} }
(void) tee_fputs("\n", PAGER); (void) tee_fputs("\n", PAGER);
} }
...@@ -1826,8 +1828,8 @@ com_tee(String *buffer, char *line __attribute__((unused))) ...@@ -1826,8 +1828,8 @@ com_tee(String *buffer, char *line __attribute__((unused)))
{ {
if (!strlen(outfile)) if (!strlen(outfile))
{ {
printf("No previous outfile available, you must give the filename!\n"); printf("No previous outfile available, you must give a filename!\n");
opt_outfile=0; opt_outfile= 0;
return 0; return 0;
} }
} }
...@@ -1835,10 +1837,10 @@ com_tee(String *buffer, char *line __attribute__((unused))) ...@@ -1835,10 +1837,10 @@ com_tee(String *buffer, char *line __attribute__((unused)))
{ {
while (isspace(*param)) while (isspace(*param))
param++; param++;
end=strmake(file_name, param, sizeof(file_name)-1); end= strmake(file_name, param, sizeof(file_name) - 1);
while (end > file_name && (isspace(end[-1]) || iscntrl(end[-1]))) while (end > file_name && (isspace(end[-1]) || iscntrl(end[-1])))
end--; end--;
end[0]=0; end[0]= 0;
strmov(outfile, file_name); strmov(outfile, file_name);
} }
if (!strlen(outfile)) if (!strlen(outfile))
...@@ -1846,12 +1848,7 @@ com_tee(String *buffer, char *line __attribute__((unused))) ...@@ -1846,12 +1848,7 @@ com_tee(String *buffer, char *line __attribute__((unused)))
printf("No outfile specified!\n"); printf("No outfile specified!\n");
return 0; return 0;
} }
if (!opt_outfile) init_tee();
{
init_tee();
opt_outfile=1;
}
tee_fprintf(stdout, "Logging to file '%s'\n", outfile);
return 0; return 0;
} }
...@@ -1861,7 +1858,6 @@ com_notee(String *buffer __attribute__((unused)), ...@@ -1861,7 +1858,6 @@ com_notee(String *buffer __attribute__((unused)),
{ {
if (opt_outfile) if (opt_outfile)
end_tee(); end_tee();
opt_outfile=0;
tee_fprintf(stdout, "Outfile disabled.\n"); tee_fprintf(stdout, "Outfile disabled.\n");
return 0; return 0;
} }
...@@ -2284,11 +2280,11 @@ com_status(String *buffer __attribute__((unused)), ...@@ -2284,11 +2280,11 @@ com_status(String *buffer __attribute__((unused)),
} }
#ifdef HAVE_OPENSSL #ifdef HAVE_OPENSSL
if (mysql.net.vio->ssl_ && SSL_get_cipher(mysql.net.vio->ssl_)) if (mysql.net.vio->ssl_ && SSL_get_cipher(mysql.net.vio->ssl_))
tee_fprintf(stdout, "SSL cipher in use is %s\n", tee_fprintf(stdout, "SSL:\t\t\tCipher in use is %s\n",
SSL_get_cipher(mysql.net.vio->ssl_)); SSL_get_cipher(mysql.net.vio->ssl_));
else else
#endif /* HAVE_OPENSSL */ #endif /* HAVE_OPENSSL */
tee_puts("SSL is not in use\n", stdout); tee_puts("SSL:\t\t\tNot in use", stdout);
} }
else else
{ {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment