Commit 84618fe0 authored by Alexey Botchkov's avatar Alexey Botchkov

Bug#37995 Error message truncation in test "innodb" in embedded mode.

   code backported from 6.0


per-file messages:
  include/my_global.h
    Remove SC_MAXWIDTH. This is unused and irrelevant nowadays.
  include/my_sys.h
    Remove errbuf declaration and unused definitions.
  mysys/my_error.c
    Remove errbuf definition and move and adjust ERRMSGSIZE.
  mysys/my_init.c
    Declare buffer on the stack and use my_snprintf.
  mysys/safemalloc.c
    Use size explicitly. It's more than enough for the message at hand.
  sql/sql_error.cc
    Use size explicitly. It's more than enough for the message at hand.
  sql/sql_parse.cc
    Declare buffer on the stack. Use my_snprintf as it will result in
    less stack space being used than by a system provided sprintf --
    this allows us to put the buffer on the stack without causing much
    trouble. Also, the use of errbuff here was not thread-safe as the
    function can be entered concurrently from multiple threads.
  sql/sql_table.cc
    Use MYSQL_ERRMSG_SIZE. Extra space is not needed as my_snprintf will
    nul terminate strings.
  storage/myisam/ha_myisam.cc
Use MYSQL_ERRMSG_SIZE.
  sql/share/errmsg.txt
    Error message truncation in test "innodb" in embedded mode
    filename in the error message can safely take up to 210 symbols.
parent 481f2415
...@@ -724,7 +724,6 @@ typedef SOCKET_SIZE_TYPE size_socket; ...@@ -724,7 +724,6 @@ typedef SOCKET_SIZE_TYPE size_socket;
#define UNSINT32 /* unsigned int32 */ #define UNSINT32 /* unsigned int32 */
/* General constants */ /* General constants */
#define SC_MAXWIDTH 256 /* Max width of screen (for error messages) */
#define FN_LEN 256 /* Max file name len */ #define FN_LEN 256 /* Max file name len */
#define FN_HEADLEN 253 /* Max length of filepart of file name */ #define FN_HEADLEN 253 /* Max length of filepart of file name */
#define FN_EXTLEN 20 /* Max length of extension (part of FN_LEN) */ #define FN_EXTLEN 20 /* Max length of extension (part of FN_LEN) */
......
...@@ -39,8 +39,6 @@ extern int NEAR my_errno; /* Last error in mysys */ ...@@ -39,8 +39,6 @@ extern int NEAR my_errno; /* Last error in mysys */
#define MYSYS_PROGRAM_DONT_USE_CURSES() { error_handler_hook = my_message_no_curses; mysys_uses_curses=0;} #define MYSYS_PROGRAM_DONT_USE_CURSES() { error_handler_hook = my_message_no_curses; mysys_uses_curses=0;}
#define MY_INIT(name); { my_progname= name; my_init(); } #define MY_INIT(name); { my_progname= name; my_init(); }
#define ERRMSGSIZE (SC_MAXWIDTH) /* Max length of a error message */
#define NRERRBUFFS (2) /* Buffers for parameters */
#define MY_FILE_ERROR ((size_t) -1) #define MY_FILE_ERROR ((size_t) -1)
/* General bitmaps for my_func's */ /* General bitmaps for my_func's */
...@@ -208,7 +206,6 @@ extern void my_large_free(uchar * ptr, myf my_flags); ...@@ -208,7 +206,6 @@ extern void my_large_free(uchar * ptr, myf my_flags);
extern int errno; /* declare errno */ extern int errno; /* declare errno */
#endif #endif
#endif /* #ifndef errno */ #endif /* #ifndef errno */
extern char NEAR errbuff[NRERRBUFFS][ERRMSGSIZE];
extern char *home_dir; /* Home directory for user */ extern char *home_dir; /* Home directory for user */
extern const char *my_progname; /* program-name (printed in errors) */ extern const char *my_progname; /* program-name (printed in errors) */
extern char NEAR curr_dir[]; /* Current directory for user */ extern char NEAR curr_dir[]; /* Current directory for user */
......
...@@ -19,6 +19,10 @@ ...@@ -19,6 +19,10 @@
#include <stdarg.h> #include <stdarg.h>
#include <m_ctype.h> #include <m_ctype.h>
/* Max length of a error message. Should be kept in sync with MYSQL_ERRMSG_SIZE. */
#define ERRMSGSIZE (512)
/* Define some external variables for error handling */ /* Define some external variables for error handling */
/* /*
...@@ -30,8 +34,6 @@ ...@@ -30,8 +34,6 @@
my_printf_error(ER_CODE, format, MYF(N), ...) my_printf_error(ER_CODE, format, MYF(N), ...)
*/ */
char NEAR errbuff[NRERRBUFFS][ERRMSGSIZE];
/* /*
Message texts are registered into a linked list of 'my_err_head' structs. Message texts are registered into a linked list of 'my_err_head' structs.
Each struct contains (1.) an array of pointers to C character strings with Each struct contains (1.) an array of pointers to C character strings with
...@@ -75,7 +77,7 @@ int my_error(int nr, myf MyFlags, ...) ...@@ -75,7 +77,7 @@ int my_error(int nr, myf MyFlags, ...)
const char *format; const char *format;
struct my_err_head *meh_p; struct my_err_head *meh_p;
va_list args; va_list args;
char ebuff[ERRMSGSIZE + 20]; char ebuff[ERRMSGSIZE];
DBUG_ENTER("my_error"); DBUG_ENTER("my_error");
DBUG_PRINT("my", ("nr: %d MyFlags: %d errno: %d", nr, MyFlags, errno)); DBUG_PRINT("my", ("nr: %d MyFlags: %d errno: %d", nr, MyFlags, errno));
...@@ -112,7 +114,7 @@ int my_error(int nr, myf MyFlags, ...) ...@@ -112,7 +114,7 @@ int my_error(int nr, myf MyFlags, ...)
int my_printf_error(uint error, const char *format, myf MyFlags, ...) int my_printf_error(uint error, const char *format, myf MyFlags, ...)
{ {
va_list args; va_list args;
char ebuff[ERRMSGSIZE+20]; char ebuff[ERRMSGSIZE];
DBUG_ENTER("my_printf_error"); DBUG_ENTER("my_printf_error");
DBUG_PRINT("my", ("nr: %d MyFlags: %d errno: %d Format: %s", DBUG_PRINT("my", ("nr: %d MyFlags: %d errno: %d Format: %s",
error, MyFlags, errno, format)); error, MyFlags, errno, format));
......
...@@ -153,9 +153,11 @@ void my_end(int infoflag) ...@@ -153,9 +153,11 @@ void my_end(int infoflag)
{ /* Test if some file is left open */ { /* Test if some file is left open */
if (my_file_opened | my_stream_opened) if (my_file_opened | my_stream_opened)
{ {
sprintf(errbuff[0],EE(EE_OPEN_WARNING),my_file_opened,my_stream_opened); char ebuff[512];
(void) my_message_no_curses(EE_OPEN_WARNING,errbuff[0],ME_BELL); my_snprintf(ebuff, sizeof(ebuff), EE(EE_OPEN_WARNING),
DBUG_PRINT("error",("%s",errbuff[0])); my_file_opened, my_stream_opened);
my_message_no_curses(EE_OPEN_WARNING, ebuff, ME_BELL);
DBUG_PRINT("error", ("%s", ebuff));
my_print_open_files(); my_print_open_files();
} }
} }
......
...@@ -147,7 +147,7 @@ void *_mymalloc(size_t size, const char *filename, uint lineno, myf MyFlags) ...@@ -147,7 +147,7 @@ void *_mymalloc(size_t size, const char *filename, uint lineno, myf MyFlags)
error_handler_hook=fatal_error_handler_hook; error_handler_hook=fatal_error_handler_hook;
if (MyFlags & (MY_FAE+MY_WME)) if (MyFlags & (MY_FAE+MY_WME))
{ {
char buff[SC_MAXWIDTH]; char buff[256];
my_errno=errno; my_errno=errno;
sprintf(buff,"Out of memory at line %d, '%s'", lineno, filename); sprintf(buff,"Out of memory at line %d, '%s'", lineno, filename);
my_message(EE_OUTOFMEMORY, buff, MYF(ME_BELL+ME_WAITTANG+ME_NOREFRESH)); my_message(EE_OUTOFMEMORY, buff, MYF(ME_BELL+ME_WAITTANG+ME_NOREFRESH));
......
...@@ -571,30 +571,30 @@ ER_ERROR_ON_READ ...@@ -571,30 +571,30 @@ ER_ERROR_ON_READ
swe "Fick fel vid lsning av '%-.200s' (Felkod %d)" swe "Fick fel vid lsning av '%-.200s' (Felkod %d)"
ukr " '%-.200s' (: %d)" ukr " '%-.200s' (: %d)"
ER_ERROR_ON_RENAME ER_ERROR_ON_RENAME
cze "Chyba p-Bi pejmenovn '%-.150s' na '%-.150s' (chybov kd: %d)" cze "Chyba p-Bi pejmenovn '%-.210s' na '%-.210s' (chybov kd: %d)"
dan "Fejl ved omdbning af '%-.150s' til '%-.150s' (Fejlkode: %d)" dan "Fejl ved omdbning af '%-.210s' til '%-.210s' (Fejlkode: %d)"
nla "Fout bij het hernoemen van '%-.150s' naar '%-.150s' (Errcode: %d)" nla "Fout bij het hernoemen van '%-.210s' naar '%-.210s' (Errcode: %d)"
eng "Error on rename of '%-.150s' to '%-.150s' (errno: %d)" eng "Error on rename of '%-.210s' to '%-.210s' (errno: %d)"
jps "'%-.150s' '%-.150s' rename ł܂ (errno: %d)", jps "'%-.210s' '%-.210s' rename ł܂ (errno: %d)",
est "Viga faili '%-.150s' mbernimetamisel '%-.150s'-ks (veakood: %d)" est "Viga faili '%-.210s' mbernimetamisel '%-.210s'-ks (veakood: %d)"
fre "Erreur en renommant '%-.150s' en '%-.150s' (Errcode: %d)" fre "Erreur en renommant '%-.210s' en '%-.210s' (Errcode: %d)"
ger "Fehler beim Umbenennen von '%-.150s' in '%-.150s' (Fehler: %d)" ger "Fehler beim Umbenennen von '%-.210s' in '%-.210s' (Fehler: %d)"
greek " '%-.150s' to '%-.150s' ( : %d)" greek " '%-.210s' to '%-.210s' ( : %d)"
hun "Hiba a '%-.150s' file atnevezesekor '%-.150s'. (hibakod: %d)" hun "Hiba a '%-.210s' file atnevezesekor '%-.210s'. (hibakod: %d)"
ita "Errore durante la rinominazione da '%-.150s' a '%-.150s' (errno: %d)" ita "Errore durante la rinominazione da '%-.210s' a '%-.210s' (errno: %d)"
jpn "'%-.150s' '%-.150s' rename Ǥޤ (errno: %d)" jpn "'%-.210s' '%-.210s' rename Ǥޤ (errno: %d)"
kor "'%-.150s' '%-.150s' ̸ (ȣ: %d)" kor "'%-.210s' '%-.210s' ̸ (ȣ: %d)"
nor "Feil ved omdping av '%-.150s' til '%-.150s' (Feilkode: %d)" nor "Feil ved omdping av '%-.210s' til '%-.210s' (Feilkode: %d)"
norwegian-ny "Feil ved omdyping av '%-.150s' til '%-.150s' (Feilkode: %d)" norwegian-ny "Feil ved omdyping av '%-.210s' til '%-.210s' (Feilkode: %d)"
pol "B?d podczas zmieniania nazwy '%-.150s' na '%-.150s' (Kod bdu: %d)" pol "B?d podczas zmieniania nazwy '%-.210s' na '%-.210s' (Kod bdu: %d)"
por "Erro ao renomear '%-.150s' para '%-.150s' (erro no. %d)" por "Erro ao renomear '%-.210s' para '%-.210s' (erro no. %d)"
rum "Eroare incercind sa renumesc '%-.150s' in '%-.150s' (errno: %d)" rum "Eroare incercind sa renumesc '%-.210s' in '%-.210s' (errno: %d)"
rus " '%-.150s' '%-.150s' (: %d)" rus " '%-.210s' '%-.210s' (: %d)"
serbian "Greka pri promeni imena '%-.150s' na '%-.150s' (errno: %d)" serbian "Greka pri promeni imena '%-.210s' na '%-.210s' (errno: %d)"
slo "Chyba pri premenovvan '%-.150s' na '%-.150s' (chybov kd: %d)" slo "Chyba pri premenovvan '%-.210s' na '%-.210s' (chybov kd: %d)"
spa "Error en el renombrado de '%-.150s' a '%-.150s' (Error: %d)" spa "Error en el renombrado de '%-.210s' a '%-.210s' (Error: %d)"
swe "Kan inte byta namn frn '%-.150s' till '%-.150s' (Felkod: %d)" swe "Kan inte byta namn frn '%-.210s' till '%-.210s' (Felkod: %d)"
ukr " '%-.150s' '%-.150s' (: %d)" ukr " '%-.210s' '%-.210s' (: %d)"
ER_ERROR_ON_WRITE ER_ERROR_ON_WRITE
cze "Chyba p-Bi zpisu do souboru '%-.200s' (chybov kd: %d)" cze "Chyba p-Bi zpisu do souboru '%-.200s' (chybov kd: %d)"
dan "Fejl ved skriving av filen '%-.200s' (Fejlkode: %d)" dan "Fejl ved skriving av filen '%-.200s' (Fejlkode: %d)"
......
...@@ -177,7 +177,7 @@ void push_warning_printf(THD *thd, MYSQL_ERROR::enum_warning_level level, ...@@ -177,7 +177,7 @@ void push_warning_printf(THD *thd, MYSQL_ERROR::enum_warning_level level,
uint code, const char *format, ...) uint code, const char *format, ...)
{ {
va_list args; va_list args;
char warning[ERRMSGSIZE+20]; char warning[MYSQL_ERRMSG_SIZE];
DBUG_ENTER("push_warning_printf"); DBUG_ENTER("push_warning_printf");
DBUG_PRINT("enter",("warning: %u", code)); DBUG_PRINT("enter",("warning: %u", code));
......
...@@ -5454,9 +5454,10 @@ bool check_stack_overrun(THD *thd, long margin, ...@@ -5454,9 +5454,10 @@ bool check_stack_overrun(THD *thd, long margin,
if ((stack_used=used_stack(thd->thread_stack,(char*) &stack_used)) >= if ((stack_used=used_stack(thd->thread_stack,(char*) &stack_used)) >=
(long) (my_thread_stack_size - margin)) (long) (my_thread_stack_size - margin))
{ {
sprintf(errbuff[0],ER(ER_STACK_OVERRUN_NEED_MORE), char ebuff[MYSQL_ERRMSG_SIZE];
stack_used,my_thread_stack_size,margin); my_snprintf(ebuff, sizeof(ebuff), ER(ER_STACK_OVERRUN_NEED_MORE),
my_message(ER_STACK_OVERRUN_NEED_MORE,errbuff[0],MYF(0)); stack_used, my_thread_stack_size, margin);
my_message(ER_STACK_OVERRUN_NEED_MORE, ebuff, MYF(ME_FATALERROR));
thd->fatal_error(); thd->fatal_error();
return 1; return 1;
} }
......
...@@ -4435,8 +4435,8 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables, ...@@ -4435,8 +4435,8 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
switch (result_code) { switch (result_code) {
case HA_ADMIN_NOT_IMPLEMENTED: case HA_ADMIN_NOT_IMPLEMENTED:
{ {
char buf[ERRMSGSIZE+20]; char buf[MYSQL_ERRMSG_SIZE];
uint length=my_snprintf(buf, ERRMSGSIZE, uint length=my_snprintf(buf, sizeof(buf),
ER(ER_CHECK_NOT_IMPLEMENTED), operator_name); ER(ER_CHECK_NOT_IMPLEMENTED), operator_name);
protocol->store(STRING_WITH_LEN("note"), system_charset_info); protocol->store(STRING_WITH_LEN("note"), system_charset_info);
protocol->store(buf, length, system_charset_info); protocol->store(buf, length, system_charset_info);
...@@ -4445,8 +4445,8 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables, ...@@ -4445,8 +4445,8 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
case HA_ADMIN_NOT_BASE_TABLE: case HA_ADMIN_NOT_BASE_TABLE:
{ {
char buf[ERRMSGSIZE+20]; char buf[MYSQL_ERRMSG_SIZE];
uint length= my_snprintf(buf, ERRMSGSIZE, uint length= my_snprintf(buf, sizeof(buf),
ER(ER_BAD_TABLE_ERROR), table_name); ER(ER_BAD_TABLE_ERROR), table_name);
protocol->store(STRING_WITH_LEN("note"), system_charset_info); protocol->store(STRING_WITH_LEN("note"), system_charset_info);
protocol->store(buf, length, system_charset_info); protocol->store(buf, length, system_charset_info);
...@@ -4573,11 +4573,12 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables, ...@@ -4573,11 +4573,12 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
case HA_ADMIN_NEEDS_UPGRADE: case HA_ADMIN_NEEDS_UPGRADE:
case HA_ADMIN_NEEDS_ALTER: case HA_ADMIN_NEEDS_ALTER:
{ {
char buf[ERRMSGSIZE]; char buf[MYSQL_ERRMSG_SIZE];
uint length; uint length;
protocol->store(STRING_WITH_LEN("error"), system_charset_info); protocol->store(STRING_WITH_LEN("error"), system_charset_info);
length=my_snprintf(buf, ERRMSGSIZE, ER(ER_TABLE_NEEDS_UPGRADE), table->table_name); length=my_snprintf(buf, sizeof(buf), ER(ER_TABLE_NEEDS_UPGRADE),
table->table_name);
protocol->store(buf, length, system_charset_info); protocol->store(buf, length, system_charset_info);
fatal_error=1; fatal_error=1;
break; break;
...@@ -4585,8 +4586,8 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables, ...@@ -4585,8 +4586,8 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
default: // Probably HA_ADMIN_INTERNAL_ERROR default: // Probably HA_ADMIN_INTERNAL_ERROR
{ {
char buf[ERRMSGSIZE+20]; char buf[MYSQL_ERRMSG_SIZE];
uint length=my_snprintf(buf, ERRMSGSIZE, uint length=my_snprintf(buf, sizeof(buf),
"Unknown - internal error %d during operation", "Unknown - internal error %d during operation",
result_code); result_code);
protocol->store(STRING_WITH_LEN("error"), system_charset_info); protocol->store(STRING_WITH_LEN("error"), system_charset_info);
......
...@@ -1257,7 +1257,7 @@ int ha_myisam::preload_keys(THD* thd, HA_CHECK_OPT *check_opt) ...@@ -1257,7 +1257,7 @@ int ha_myisam::preload_keys(THD* thd, HA_CHECK_OPT *check_opt)
ulonglong map; ulonglong map;
TABLE_LIST *table_list= table->pos_in_table_list; TABLE_LIST *table_list= table->pos_in_table_list;
my_bool ignore_leaves= table_list->ignore_leaves; my_bool ignore_leaves= table_list->ignore_leaves;
char buf[ERRMSGSIZE+20]; char buf[MYSQL_ERRMSG_SIZE];
DBUG_ENTER("ha_myisam::preload_keys"); DBUG_ENTER("ha_myisam::preload_keys");
...@@ -1285,7 +1285,7 @@ int ha_myisam::preload_keys(THD* thd, HA_CHECK_OPT *check_opt) ...@@ -1285,7 +1285,7 @@ int ha_myisam::preload_keys(THD* thd, HA_CHECK_OPT *check_opt)
errmsg= "Failed to allocate buffer"; errmsg= "Failed to allocate buffer";
break; break;
default: default:
my_snprintf(buf, ERRMSGSIZE, my_snprintf(buf, sizeof(buf),
"Failed to read from index file (errno: %d)", my_errno); "Failed to read from index file (errno: %d)", my_errno);
errmsg= buf; errmsg= buf;
} }
......
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