Skip to content

Commit 78fa042

Browse files
author
Tor Didriksen
committed
Bug#25739702 ENABLE UBSAN ON 32BIT PLATFORMS
Increase DEFAULT_THREAD_STACK for 32bit UBSAN builds. Also: fix my_convert() which did unaligned read/write. Also: fix signed integer overflow in TIME_to_gmt_sec() and Time_zone_offset::TIME_to_gmt_sec()
1 parent 5af23e7 commit 78fa042

File tree

4 files changed

+12
-10
lines changed

4 files changed

+12
-10
lines changed

include/my_thread.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
*/
5252
#if defined(__sparc) && (defined(__SUNPRO_CC) || defined(__SUNPRO_C))
5353
#define STACK_MULTIPLIER 2UL
54+
#elif defined HAVE_UBSAN && SIZEOF_CHARP == 4
55+
#define STACK_MULTIPLIER 3UL
5456
#else
5557
#define STACK_MULTIPLIER 1UL
5658
#endif

sql/log.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1476,7 +1476,7 @@ bool Query_logger::slow_log_write(THD *thd, const char *query,
14761476
*current_handler ;)
14771477
{
14781478
error|= (*current_handler++)->log_slow(thd, current_utime,
1479-
(thd->start_time.tv_sec * 1000000) +
1479+
(thd->start_time.tv_sec * 1000000ULL) +
14801480
thd->start_time.tv_usec,
14811481
user_host_buff, user_host_len,
14821482
query_utime, lock_utime, is_command,

sql/tztime.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -953,7 +953,7 @@ static my_time_t
953953
TIME_to_gmt_sec(const MYSQL_TIME *t, const TIME_ZONE_INFO *sp,
954954
bool *in_dst_time_gap)
955955
{
956-
my_time_t local_t;
956+
longlong local_t;
957957
uint saved_seconds;
958958
uint i;
959959
int shift= 0;
@@ -1036,16 +1036,16 @@ TIME_to_gmt_sec(const MYSQL_TIME *t, const TIME_ZONE_INFO *sp,
10361036
beginning of the gap.
10371037
*/
10381038
*in_dst_time_gap= 1;
1039-
local_t= sp->revts[i] - sp->revtis[i].rt_offset + saved_seconds;
1039+
local_t= sp->revts[i] + saved_seconds - sp->revtis[i].rt_offset;
10401040
}
10411041
else
1042-
local_t= local_t - sp->revtis[i].rt_offset + saved_seconds;
1042+
local_t= local_t + saved_seconds - sp->revtis[i].rt_offset;
10431043

10441044
/* check for TIMESTAMP_MAX_VALUE was already done above */
10451045
if (local_t < TIMESTAMP_MIN_VALUE)
10461046
local_t= 0;
10471047

1048-
DBUG_RETURN(local_t);
1048+
DBUG_RETURN(static_cast<my_time_t>(local_t));
10491049
}
10501050

10511051

@@ -1418,7 +1418,7 @@ Time_zone_offset::TIME_to_gmt_sec(
14181418
const MYSQL_TIME *t,
14191419
bool *in_dst_time_gap MY_ATTRIBUTE((unused))) const
14201420
{
1421-
my_time_t local_t;
1421+
longlong local_t;
14221422
int shift= 0;
14231423

14241424
/*
@@ -1447,7 +1447,7 @@ Time_zone_offset::TIME_to_gmt_sec(
14471447
}
14481448

14491449
if (local_t >= TIMESTAMP_MIN_VALUE && local_t <= TIMESTAMP_MAX_VALUE)
1450-
return local_t;
1450+
return static_cast<my_time_t>(local_t);
14511451

14521452
/* range error*/
14531453
return 0;

strings/ctype.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1041,7 +1041,7 @@ my_convert(char *to, size_t to_length, const CHARSET_INFO *to_cs,
10411041

10421042
length= length2= MY_MIN(to_length, from_length);
10431043

1044-
#if defined(__i386__)
1044+
#if defined(__i386__) || defined(_WIN32) || defined(__x86_64__)
10451045
/*
10461046
Special loop for i386, it allows to refer to a
10471047
non-aligned memory block as UINT32, which makes
@@ -1051,9 +1051,9 @@ my_convert(char *to, size_t to_length, const CHARSET_INFO *to_cs,
10511051
*/
10521052
for ( ; length >= 4; length-= 4, from+= 4, to+= 4)
10531053
{
1054-
if ((*(uint32*)from) & 0x80808080)
1054+
if (uint4korr(from) & 0x80808080)
10551055
break;
1056-
*((uint32*) to)= *((const uint32*) from);
1056+
int4store(to, uint4korr(from));
10571057
}
10581058
#endif /* __i386__ */
10591059

0 commit comments

Comments
 (0)