BUG#24807826: UINT3KORR SHOULD STOP READING FOUR INSTEAD OF
THREE BYTES ON X86 Analysis: ========= The macro uint3korr reads 4 bytes of data instead of 3 on on x86 machines. Multiple definitions were created for this macro for optimization in WIN32. The idea was to optimize reading of 3 byte ints by reading an ordinary int and masking away the unused byte. However this is an undefined behavior. It will be an issue unless users are aware of allocating an extra byte for using this macro. Fix: ==== Removing the definition which reads 4 bytes of data. The only definition of this macro would now read just 3 bytes of data thus prohibiting the usage of an extra byte. Note: ===== This is a backport of Patches #5 and #6 for Bug#17922198.
This commit is contained in:
parent
e619295e1b
commit
af84921d26
@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
|
||||
Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@ -1064,19 +1064,9 @@ typedef char my_bool; /* Small bool */
|
||||
((uint32) (uchar) (A)[0])))
|
||||
#define sint4korr(A) (*((long *) (A)))
|
||||
#define uint2korr(A) (*((uint16 *) (A)))
|
||||
#if defined(HAVE_purify) && !defined(_WIN32)
|
||||
#define uint3korr(A) (uint32) (((uint32) ((uchar) (A)[0])) +\
|
||||
(((uint32) ((uchar) (A)[1])) << 8) +\
|
||||
(((uint32) ((uchar) (A)[2])) << 16))
|
||||
#else
|
||||
/*
|
||||
ATTENTION !
|
||||
|
||||
Please, note, uint3korr reads 4 bytes (not 3) !
|
||||
It means, that you have to provide enough allocated space !
|
||||
*/
|
||||
#define uint3korr(A) (long) (*((unsigned int *) (A)) & 0xFFFFFF)
|
||||
#endif /* HAVE_purify && !_WIN32 */
|
||||
#define uint4korr(A) (*((uint32 *) (A)))
|
||||
#define uint5korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\
|
||||
(((uint32) ((uchar) (A)[1])) << 8) +\
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@ -179,12 +179,10 @@ my_bool net_realloc(NET *net, size_t length)
|
||||
pkt_length = (length+IO_SIZE-1) & ~(IO_SIZE-1);
|
||||
/*
|
||||
We must allocate some extra bytes for the end 0 and to be able to
|
||||
read big compressed blocks + 1 safety byte since uint3korr() in
|
||||
my_real_read() may actually read 4 bytes depending on build flags and
|
||||
platform.
|
||||
read big compressed blocks in my_real_read().
|
||||
*/
|
||||
if (!(buff= (uchar*) my_realloc((char*) net->buff, pkt_length +
|
||||
NET_HEADER_SIZE + COMP_HEADER_SIZE + 1,
|
||||
NET_HEADER_SIZE + COMP_HEADER_SIZE,
|
||||
MYF(MY_WME))))
|
||||
{
|
||||
/* @todo: 1 and 2 codes are identical. */
|
||||
@ -951,12 +949,11 @@ my_real_read(NET *net, size_t *complen)
|
||||
if (net->compress)
|
||||
{
|
||||
/*
|
||||
The following uint3korr() may read 4 bytes, so make sure we don't
|
||||
read unallocated or uninitialized memory. The right-hand expression
|
||||
must match the size of the buffer allocated in net_realloc().
|
||||
The right-hand expression must match the size of the buffer
|
||||
allocated in net_realloc().
|
||||
*/
|
||||
DBUG_ASSERT(net->where_b + NET_HEADER_SIZE + sizeof(uint32) <=
|
||||
net->max_packet + NET_HEADER_SIZE + COMP_HEADER_SIZE + 1);
|
||||
net->max_packet + NET_HEADER_SIZE + COMP_HEADER_SIZE);
|
||||
/*
|
||||
If the packet is compressed then complen > 0 and contains the
|
||||
number of bytes in the uncompressed packet
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
|
||||
/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
@ -589,10 +589,9 @@ static int init_rr_cache(THD *thd, READ_RECORD *info)
|
||||
rec_cache_size= info->cache_records*info->reclength;
|
||||
info->rec_cache_size= info->cache_records*info->ref_length;
|
||||
|
||||
// We have to allocate one more byte to use uint3korr (see comments for it)
|
||||
if (info->cache_records <= 2 ||
|
||||
!(info->cache=(uchar*) my_malloc_lock(rec_cache_size+info->cache_records*
|
||||
info->struct_length+1,
|
||||
info->struct_length,
|
||||
MYF(0))))
|
||||
DBUG_RETURN(1);
|
||||
#ifdef HAVE_purify
|
||||
|
Loading…
x
Reference in New Issue
Block a user