Skip to content

Commit c4bf4b7

Browse files
committed
Fixed access to undefined memory found by valgrind and MSAN
When my_vsnprintf() is patched, the code protected disabled with 'WAITING_FOR_BUGFIX_TO_VSPRINTF' should be enabled again. Also all %b formats in this patch should be revert to %s again
1 parent dcc0baf commit c4bf4b7

File tree

13 files changed

+42
-63
lines changed

13 files changed

+42
-63
lines changed

extra/replace.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ typedef struct st_pointer_array { /* when using array-strings */
6464
#define LAST_CHAR_CODE 259
6565

6666
typedef struct st_replace {
67-
my_bool found;
67+
uint8 found;
6868
struct st_replace *next[256];
6969
} REPLACE;
7070

@@ -654,7 +654,13 @@ static REPLACE *init_replace(char * *from, char * *to,uint count,
654654
for (i=1 ; i <= found_sets ; i++)
655655
{
656656
pos=from[found_set[i-1].table_offset];
657-
rep_str[i].found= (my_bool) (!memcmp(pos,"\\^",3) ? 2 : 1);
657+
/*
658+
Test if we are matching start of string (\^)
659+
We can't use bcmp() here as pos may be only 1 character and
660+
that would confuse MSAN.
661+
*/
662+
rep_str[i].found= (uint8) ((pos[0] == '\\' && pos[1] == '^' &&
663+
pos[2] == 0) ? 2 : 1);
658664
rep_str[i].replace_string=to_array[found_set[i-1].table_offset];
659665
rep_str[i].to_offset=found_set[i-1].found_offset-start_at_word(pos);
660666
rep_str[i].from_offset=found_set[i-1].found_offset-replace_len(pos)+

include/my_dbug.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,10 @@ extern void _db_enter_(const char *_func_, const char *_file_, uint _line_,
5252
extern void _db_return_(struct _db_stack_frame_ *_stack_frame_);
5353
extern int _db_pargs_(uint _line_,const char *keyword);
5454
extern void _db_doprnt_(const char *format,...)
55-
ATTRIBUTE_FORMAT(printf, 1, 2);
55+
#ifdef WAITING_FOR_BUGFIX_TO_VSPRINTF
56+
ATTRIBUTE_FORMAT(printf, 1, 2)
57+
#endif
58+
;
5659
extern void _db_dump_(uint _line_,const char *keyword,
5760
const unsigned char *memory, size_t length);
5861
extern void _db_end_(void);

mysql-test/main/sum_distinct-big.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#
44

55
--source include/big_test.inc
6+
# Test will take more than one hour with valgrind
7+
--source include/not_valgrind.inc
68
--source include/have_innodb.inc
79
--source include/have_sequence.inc
810

mysql-test/valgrind.supp

Lines changed: 0 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -750,45 +750,6 @@
750750
# Note the wildcard in the (mangled) function signatures of
751751
# write_keys() and find_all_keys().
752752
# They both return ha_rows, which is platform dependent.
753-
#
754-
# The '...' wildcards are for 'fun:inline_mysql_file_write' and
755-
# 'fun:find_all_keys' which *may* be inlined.
756-
{
757-
Bug#12856915 VALGRIND FAILURE IN FILESORT/CREATE_SORT_INDEX / one
758-
Memcheck:Param
759-
write(buf)
760-
obj:*/libpthread*.so
761-
fun:my_write
762-
...
763-
fun:my_b_flush_io_cache
764-
fun:_my_b_write
765-
fun:_Z*10write_keysP13st_sort_paramPPhjP11st_io_cacheS4_
766-
...
767-
fun:_Z8filesortP3THDP5TABLEP13st_sort_fieldjP10SQL_SELECTybPy
768-
}
769-
770-
{
771-
Bug#12856915 VALGRIND FAILURE IN FILESORT/CREATE_SORT_INDEX / two
772-
Memcheck:Param
773-
write(buf)
774-
obj:*/libpthread*.so
775-
fun:my_write
776-
...
777-
fun:my_b_flush_io_cache
778-
fun:_Z15merge_many_buffP13st_sort_paramPhP10st_buffpekPjP11st_io_cache
779-
fun:_Z8filesortP3THDP5TABLEP13st_sort_fieldjP10SQL_SELECTybPy
780-
}
781-
782-
{
783-
Bug#12856915 VALGRIND FAILURE IN FILESORT/CREATE_SORT_INDEX / three
784-
Memcheck:Param
785-
write(buf)
786-
obj:*/libpthread*.so
787-
fun:my_write
788-
...
789-
fun:my_b_flush_io_cache
790-
fun:_Z8filesortP3THDP5TABLEP13st_sort_fieldjP10SQL_SELECTybPy
791-
}
792753

793754
{
794755
OpenSSL still reachable.

plugin/type_inet/sql_type_inet.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1411,7 +1411,7 @@ void Type_handler_inet6::sort_length(THD *thd,
14111411
const Type_std_attributes *item,
14121412
SORT_FIELD_ATTR *attr) const
14131413
{
1414-
attr->length= Inet6::binary_length();
1414+
attr->original_length= attr->length= Inet6::binary_length();
14151415
attr->suffix_length= 0;
14161416
}
14171417

sql/item_subselect.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -728,8 +728,8 @@ bool Item_subselect::exec()
728728
QT_WITHOUT_INTRODUCERS));
729729

730730
push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE,
731-
ER_UNKNOWN_ERROR, "DBUG: Item_subselect::exec %.*s",
732-
print.length(),print.c_ptr());
731+
ER_UNKNOWN_ERROR, "DBUG: Item_subselect::exec %.*b",
732+
print.length(),print.ptr());
733733
);
734734
/*
735735
Do not execute subselect in case of a fatal error

sql/protocol.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1218,7 +1218,7 @@ bool Protocol_text::store(const char *from, size_t length,
12181218
{
12191219
CHARSET_INFO *tocs= this->thd->variables.character_set_results;
12201220
#ifndef DBUG_OFF
1221-
DBUG_PRINT("info", ("Protocol_text::store field %u (%u): %.*s", field_pos,
1221+
DBUG_PRINT("info", ("Protocol_text::store field %u (%u): %.*b", field_pos,
12221222
field_count, (int) length, (length == 0 ? "" : from)));
12231223
DBUG_ASSERT(field_handlers == 0 || field_pos < field_count);
12241224
DBUG_ASSERT(valid_handler(field_pos, PROTOCOL_SEND_STRING));

sql/signal_handler.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,9 @@ static inline void output_core_info()
5252
char buff[PATH_MAX];
5353
ssize_t len;
5454
int fd;
55-
if ((len= readlink("/proc/self/cwd", buff, sizeof(buff))) >= 0)
55+
if ((len= readlink("/proc/self/cwd", buff, sizeof(buff)-1)) >= 0)
5656
{
57+
buff[len]= 0;
5758
my_safe_printf_stderr("Writing a core file...\nWorking directory at %.*s\n",
5859
(int) len, buff);
5960
}

sql/tztime.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1900,7 +1900,7 @@ tz_load_from_open_tables(const String *tz_name, TABLE_LIST *tz_tables)
19001900
Most probably user has mistyped time zone name, so no need to bark here
19011901
unless we need it for debugging.
19021902
*/
1903-
sql_print_error("Can't find description of time zone '%.*s'",
1903+
sql_print_error("Can't find description of time zone '%.*b'",
19041904
tz_name->length(), tz_name->ptr());
19051905
#endif
19061906
goto end;

storage/maria/ma_bitmap.c

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -519,9 +519,10 @@ my_bool _ma_bitmap_flush_all(MARIA_SHARE *share)
519519
#ifdef EXTRA_DEBUG_BITMAP
520520
{
521521
char tmp[MAX_BITMAP_INFO_LENGTH];
522-
_ma_get_bitmap_description(bitmap, bitmap->map, bitmap->page, tmp);
522+
size_t len;
523+
len= _ma_get_bitmap_description(bitmap, bitmap->map, bitmap->page, tmp);
523524
(void) translog_log_debug_info(0, LOGREC_DEBUG_INFO_QUERY,
524-
(uchar*) tmp, strlen(tmp));
525+
(uchar*) tmp, len);
525526
}
526527
#endif
527528

@@ -957,13 +958,13 @@ void _ma_print_bitmap(MARIA_FILE_BITMAP *bitmap, uchar *data,
957958
Return content of bitmap as a printable string
958959
*/
959960

960-
void _ma_get_bitmap_description(MARIA_FILE_BITMAP *bitmap,
961-
uchar *bitmap_data,
962-
pgcache_page_no_t page,
963-
char *out)
961+
size_t _ma_get_bitmap_description(MARIA_FILE_BITMAP *bitmap,
962+
uchar *bitmap_data,
963+
pgcache_page_no_t page,
964+
char *out)
964965
{
965966
uchar *pos, *end;
966-
uint count=0, dot_printed= 0, len;
967+
size_t count=0, dot_printed= 0, len;
967968
char buff[80], last[80];
968969

969970
page++;
@@ -1000,6 +1001,7 @@ void _ma_get_bitmap_description(MARIA_FILE_BITMAP *bitmap,
10001001
memcpy(out+len, buff, count);
10011002
out[len + count]= '\n';
10021003
out[len + count + 1]= 0;
1004+
return len + count + 1;
10031005
}
10041006

10051007

0 commit comments

Comments
 (0)