Skip to content

Commit cf0d0a5

Browse files
author
Alexey Botchkov
committed
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.
1 parent b6542a3 commit cf0d0a5

File tree

10 files changed

+52
-50
lines changed

10 files changed

+52
-50
lines changed

include/my_global.h

-1
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,6 @@ typedef SOCKET_SIZE_TYPE size_socket;
724724
#define UNSINT32 /* unsigned int32 */
725725

726726
/* General constants */
727-
#define SC_MAXWIDTH 256 /* Max width of screen (for error messages) */
728727
#define FN_LEN 256 /* Max file name len */
729728
#define FN_HEADLEN 253 /* Max length of filepart of file name */
730729
#define FN_EXTLEN 20 /* Max length of extension (part of FN_LEN) */

include/my_sys.h

-3
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,6 @@ extern int NEAR my_errno; /* Last error in mysys */
3939
#define MYSYS_PROGRAM_DONT_USE_CURSES() { error_handler_hook = my_message_no_curses; mysys_uses_curses=0;}
4040
#define MY_INIT(name); { my_progname= name; my_init(); }
4141

42-
#define ERRMSGSIZE (SC_MAXWIDTH) /* Max length of a error message */
43-
#define NRERRBUFFS (2) /* Buffers for parameters */
4442
#define MY_FILE_ERROR ((size_t) -1)
4543

4644
/* General bitmaps for my_func's */
@@ -208,7 +206,6 @@ extern void my_large_free(uchar * ptr, myf my_flags);
208206
extern int errno; /* declare errno */
209207
#endif
210208
#endif /* #ifndef errno */
211-
extern char NEAR errbuff[NRERRBUFFS][ERRMSGSIZE];
212209
extern char *home_dir; /* Home directory for user */
213210
extern const char *my_progname; /* program-name (printed in errors) */
214211
extern char NEAR curr_dir[]; /* Current directory for user */

mysys/my_error.c

+6-4
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
#include <stdarg.h>
2020
#include <m_ctype.h>
2121

22+
/* Max length of a error message. Should be kept in sync with MYSQL_ERRMSG_SIZE. */
23+
#define ERRMSGSIZE (512)
24+
25+
2226
/* Define some external variables for error handling */
2327

2428
/*
@@ -30,8 +34,6 @@
3034
my_printf_error(ER_CODE, format, MYF(N), ...)
3135
*/
3236

33-
char NEAR errbuff[NRERRBUFFS][ERRMSGSIZE];
34-
3537
/*
3638
Message texts are registered into a linked list of 'my_err_head' structs.
3739
Each struct contains (1.) an array of pointers to C character strings with
@@ -75,7 +77,7 @@ int my_error(int nr, myf MyFlags, ...)
7577
const char *format;
7678
struct my_err_head *meh_p;
7779
va_list args;
78-
char ebuff[ERRMSGSIZE + 20];
80+
char ebuff[ERRMSGSIZE];
7981
DBUG_ENTER("my_error");
8082
DBUG_PRINT("my", ("nr: %d MyFlags: %d errno: %d", nr, MyFlags, errno));
8183

@@ -112,7 +114,7 @@ int my_error(int nr, myf MyFlags, ...)
112114
int my_printf_error(uint error, const char *format, myf MyFlags, ...)
113115
{
114116
va_list args;
115-
char ebuff[ERRMSGSIZE+20];
117+
char ebuff[ERRMSGSIZE];
116118
DBUG_ENTER("my_printf_error");
117119
DBUG_PRINT("my", ("nr: %d MyFlags: %d errno: %d Format: %s",
118120
error, MyFlags, errno, format));

mysys/my_init.c

+5-3
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,11 @@ void my_end(int infoflag)
153153
{ /* Test if some file is left open */
154154
if (my_file_opened | my_stream_opened)
155155
{
156-
sprintf(errbuff[0],EE(EE_OPEN_WARNING),my_file_opened,my_stream_opened);
157-
(void) my_message_no_curses(EE_OPEN_WARNING,errbuff[0],ME_BELL);
158-
DBUG_PRINT("error",("%s",errbuff[0]));
156+
char ebuff[512];
157+
my_snprintf(ebuff, sizeof(ebuff), EE(EE_OPEN_WARNING),
158+
my_file_opened, my_stream_opened);
159+
my_message_no_curses(EE_OPEN_WARNING, ebuff, ME_BELL);
160+
DBUG_PRINT("error", ("%s", ebuff));
159161
my_print_open_files();
160162
}
161163
}

mysys/safemalloc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ void *_mymalloc(size_t size, const char *filename, uint lineno, myf MyFlags)
147147
error_handler_hook=fatal_error_handler_hook;
148148
if (MyFlags & (MY_FAE+MY_WME))
149149
{
150-
char buff[SC_MAXWIDTH];
150+
char buff[256];
151151
my_errno=errno;
152152
sprintf(buff,"Out of memory at line %d, '%s'", lineno, filename);
153153
my_message(EE_OUTOFMEMORY, buff, MYF(ME_BELL+ME_WAITTANG+ME_NOREFRESH));

sql/share/errmsg.txt

+24-24
Original file line numberDiff line numberDiff line change
@@ -571,30 +571,30 @@ ER_ERROR_ON_READ
571571
swe "Fick fel vid l�sning av '%-.200s' (Felkod %d)"
572572
ukr "�� ���� ��������� ���� '%-.200s' (�������: %d)"
573573
ER_ERROR_ON_RENAME
574-
cze "Chyba p-B�i p�ejmenov�n� '%-.150s' na '%-.150s' (chybov� k�d: %d)"
575-
dan "Fejl ved omd�bning af '%-.150s' til '%-.150s' (Fejlkode: %d)"
576-
nla "Fout bij het hernoemen van '%-.150s' naar '%-.150s' (Errcode: %d)"
577-
eng "Error on rename of '%-.150s' to '%-.150s' (errno: %d)"
578-
jps "'%-.150s' �� '%-.150s' �� rename �ł��܂��� (errno: %d)",
579-
est "Viga faili '%-.150s' �mbernimetamisel '%-.150s'-ks (veakood: %d)"
580-
fre "Erreur en renommant '%-.150s' en '%-.150s' (Errcode: %d)"
581-
ger "Fehler beim Umbenennen von '%-.150s' in '%-.150s' (Fehler: %d)"
582-
greek "�������� ���� ��� ����������� ��� ������� '%-.150s' to '%-.150s' (������� ������: %d)"
583-
hun "Hiba a '%-.150s' file atnevezesekor '%-.150s'. (hibakod: %d)"
584-
ita "Errore durante la rinominazione da '%-.150s' a '%-.150s' (errno: %d)"
585-
jpn "'%-.150s' �� '%-.150s' �� rename �Ǥ��ޤ��� (errno: %d)"
586-
kor "'%-.150s'�� '%-.150s'�� �̸� ������ ���� (������ȣ: %d)"
587-
nor "Feil ved omd�ping av '%-.150s' til '%-.150s' (Feilkode: %d)"
588-
norwegian-ny "Feil ved omd�yping av '%-.150s' til '%-.150s' (Feilkode: %d)"
589-
pol "B�?d podczas zmieniania nazwy '%-.150s' na '%-.150s' (Kod b��du: %d)"
590-
por "Erro ao renomear '%-.150s' para '%-.150s' (erro no. %d)"
591-
rum "Eroare incercind sa renumesc '%-.150s' in '%-.150s' (errno: %d)"
592-
rus "������ ��� �������������� '%-.150s' � '%-.150s' (������: %d)"
593-
serbian "Gre�ka pri promeni imena '%-.150s' na '%-.150s' (errno: %d)"
594-
slo "Chyba pri premenov�van� '%-.150s' na '%-.150s' (chybov� k�d: %d)"
595-
spa "Error en el renombrado de '%-.150s' a '%-.150s' (Error: %d)"
596-
swe "Kan inte byta namn fr�n '%-.150s' till '%-.150s' (Felkod: %d)"
597-
ukr "�� ���� ������������� '%-.150s' � '%-.150s' (�������: %d)"
574+
cze "Chyba p-B�i p�ejmenov�n� '%-.210s' na '%-.210s' (chybov� k�d: %d)"
575+
dan "Fejl ved omd�bning af '%-.210s' til '%-.210s' (Fejlkode: %d)"
576+
nla "Fout bij het hernoemen van '%-.210s' naar '%-.210s' (Errcode: %d)"
577+
eng "Error on rename of '%-.210s' to '%-.210s' (errno: %d)"
578+
jps "'%-.210s' �� '%-.210s' �� rename �ł��܂��� (errno: %d)",
579+
est "Viga faili '%-.210s' �mbernimetamisel '%-.210s'-ks (veakood: %d)"
580+
fre "Erreur en renommant '%-.210s' en '%-.210s' (Errcode: %d)"
581+
ger "Fehler beim Umbenennen von '%-.210s' in '%-.210s' (Fehler: %d)"
582+
greek "�������� ���� ��� ����������� ��� ������� '%-.210s' to '%-.210s' (������� ������: %d)"
583+
hun "Hiba a '%-.210s' file atnevezesekor '%-.210s'. (hibakod: %d)"
584+
ita "Errore durante la rinominazione da '%-.210s' a '%-.210s' (errno: %d)"
585+
jpn "'%-.210s' �� '%-.210s' �� rename �Ǥ��ޤ��� (errno: %d)"
586+
kor "'%-.210s'�� '%-.210s'�� �̸� ������ ���� (������ȣ: %d)"
587+
nor "Feil ved omd�ping av '%-.210s' til '%-.210s' (Feilkode: %d)"
588+
norwegian-ny "Feil ved omd�yping av '%-.210s' til '%-.210s' (Feilkode: %d)"
589+
pol "B�?d podczas zmieniania nazwy '%-.210s' na '%-.210s' (Kod b��du: %d)"
590+
por "Erro ao renomear '%-.210s' para '%-.210s' (erro no. %d)"
591+
rum "Eroare incercind sa renumesc '%-.210s' in '%-.210s' (errno: %d)"
592+
rus "������ ��� �������������� '%-.210s' � '%-.210s' (������: %d)"
593+
serbian "Gre�ka pri promeni imena '%-.210s' na '%-.210s' (errno: %d)"
594+
slo "Chyba pri premenov�van� '%-.210s' na '%-.210s' (chybov� k�d: %d)"
595+
spa "Error en el renombrado de '%-.210s' a '%-.210s' (Error: %d)"
596+
swe "Kan inte byta namn fr�n '%-.210s' till '%-.210s' (Felkod: %d)"
597+
ukr "�� ���� ������������� '%-.210s' � '%-.210s' (�������: %d)"
598598
ER_ERROR_ON_WRITE
599599
cze "Chyba p-B�i z�pisu do souboru '%-.200s' (chybov� k�d: %d)"
600600
dan "Fejl ved skriving av filen '%-.200s' (Fejlkode: %d)"

sql/sql_error.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ void push_warning_printf(THD *thd, MYSQL_ERROR::enum_warning_level level,
177177
uint code, const char *format, ...)
178178
{
179179
va_list args;
180-
char warning[ERRMSGSIZE+20];
180+
char warning[MYSQL_ERRMSG_SIZE];
181181
DBUG_ENTER("push_warning_printf");
182182
DBUG_PRINT("enter",("warning: %u", code));
183183

sql/sql_parse.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -5454,9 +5454,10 @@ bool check_stack_overrun(THD *thd, long margin,
54545454
if ((stack_used=used_stack(thd->thread_stack,(char*) &stack_used)) >=
54555455
(long) (my_thread_stack_size - margin))
54565456
{
5457-
sprintf(errbuff[0],ER(ER_STACK_OVERRUN_NEED_MORE),
5458-
stack_used,my_thread_stack_size,margin);
5459-
my_message(ER_STACK_OVERRUN_NEED_MORE,errbuff[0],MYF(0));
5457+
char ebuff[MYSQL_ERRMSG_SIZE];
5458+
my_snprintf(ebuff, sizeof(ebuff), ER(ER_STACK_OVERRUN_NEED_MORE),
5459+
stack_used, my_thread_stack_size, margin);
5460+
my_message(ER_STACK_OVERRUN_NEED_MORE, ebuff, MYF(ME_FATALERROR));
54605461
thd->fatal_error();
54615462
return 1;
54625463
}

sql/sql_table.cc

+9-8
Original file line numberDiff line numberDiff line change
@@ -4435,8 +4435,8 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
44354435
switch (result_code) {
44364436
case HA_ADMIN_NOT_IMPLEMENTED:
44374437
{
4438-
char buf[ERRMSGSIZE+20];
4439-
uint length=my_snprintf(buf, ERRMSGSIZE,
4438+
char buf[MYSQL_ERRMSG_SIZE];
4439+
uint length=my_snprintf(buf, sizeof(buf),
44404440
ER(ER_CHECK_NOT_IMPLEMENTED), operator_name);
44414441
protocol->store(STRING_WITH_LEN("note"), system_charset_info);
44424442
protocol->store(buf, length, system_charset_info);
@@ -4445,8 +4445,8 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
44454445

44464446
case HA_ADMIN_NOT_BASE_TABLE:
44474447
{
4448-
char buf[ERRMSGSIZE+20];
4449-
uint length= my_snprintf(buf, ERRMSGSIZE,
4448+
char buf[MYSQL_ERRMSG_SIZE];
4449+
uint length= my_snprintf(buf, sizeof(buf),
44504450
ER(ER_BAD_TABLE_ERROR), table_name);
44514451
protocol->store(STRING_WITH_LEN("note"), system_charset_info);
44524452
protocol->store(buf, length, system_charset_info);
@@ -4573,20 +4573,21 @@ static bool mysql_admin_table(THD* thd, TABLE_LIST* tables,
45734573
case HA_ADMIN_NEEDS_UPGRADE:
45744574
case HA_ADMIN_NEEDS_ALTER:
45754575
{
4576-
char buf[ERRMSGSIZE];
4576+
char buf[MYSQL_ERRMSG_SIZE];
45774577
uint length;
45784578

45794579
protocol->store(STRING_WITH_LEN("error"), system_charset_info);
4580-
length=my_snprintf(buf, ERRMSGSIZE, ER(ER_TABLE_NEEDS_UPGRADE), table->table_name);
4580+
length=my_snprintf(buf, sizeof(buf), ER(ER_TABLE_NEEDS_UPGRADE),
4581+
table->table_name);
45814582
protocol->store(buf, length, system_charset_info);
45824583
fatal_error=1;
45834584
break;
45844585
}
45854586

45864587
default: // Probably HA_ADMIN_INTERNAL_ERROR
45874588
{
4588-
char buf[ERRMSGSIZE+20];
4589-
uint length=my_snprintf(buf, ERRMSGSIZE,
4589+
char buf[MYSQL_ERRMSG_SIZE];
4590+
uint length=my_snprintf(buf, sizeof(buf),
45904591
"Unknown - internal error %d during operation",
45914592
result_code);
45924593
protocol->store(STRING_WITH_LEN("error"), system_charset_info);

storage/myisam/ha_myisam.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -1257,7 +1257,7 @@ int ha_myisam::preload_keys(THD* thd, HA_CHECK_OPT *check_opt)
12571257
ulonglong map;
12581258
TABLE_LIST *table_list= table->pos_in_table_list;
12591259
my_bool ignore_leaves= table_list->ignore_leaves;
1260-
char buf[ERRMSGSIZE+20];
1260+
char buf[MYSQL_ERRMSG_SIZE];
12611261

12621262
DBUG_ENTER("ha_myisam::preload_keys");
12631263

@@ -1285,7 +1285,7 @@ int ha_myisam::preload_keys(THD* thd, HA_CHECK_OPT *check_opt)
12851285
errmsg= "Failed to allocate buffer";
12861286
break;
12871287
default:
1288-
my_snprintf(buf, ERRMSGSIZE,
1288+
my_snprintf(buf, sizeof(buf),
12891289
"Failed to read from index file (errno: %d)", my_errno);
12901290
errmsg= buf;
12911291
}

0 commit comments

Comments
 (0)