Skip to content

Commit af84921

Browse files
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.
1 parent e619295 commit af84921

File tree

3 files changed

+9
-23
lines changed

3 files changed

+9
-23
lines changed

include/my_global.h

+1-11
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
2+
Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved.
33
44
This program is free software; you can redistribute it and/or modify
55
it under the terms of the GNU General Public License as published by
@@ -1064,19 +1064,9 @@ typedef char my_bool; /* Small bool */
10641064
((uint32) (uchar) (A)[0])))
10651065
#define sint4korr(A) (*((long *) (A)))
10661066
#define uint2korr(A) (*((uint16 *) (A)))
1067-
#if defined(HAVE_purify) && !defined(_WIN32)
10681067
#define uint3korr(A) (uint32) (((uint32) ((uchar) (A)[0])) +\
10691068
(((uint32) ((uchar) (A)[1])) << 8) +\
10701069
(((uint32) ((uchar) (A)[2])) << 16))
1071-
#else
1072-
/*
1073-
ATTENTION !
1074-
1075-
Please, note, uint3korr reads 4 bytes (not 3) !
1076-
It means, that you have to provide enough allocated space !
1077-
*/
1078-
#define uint3korr(A) (long) (*((unsigned int *) (A)) & 0xFFFFFF)
1079-
#endif /* HAVE_purify && !_WIN32 */
10801070
#define uint4korr(A) (*((uint32 *) (A)))
10811071
#define uint5korr(A) ((ulonglong)(((uint32) ((uchar) (A)[0])) +\
10821072
(((uint32) ((uchar) (A)[1])) << 8) +\

sql/net_serv.cc

+6-9
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2016, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
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)
179179
pkt_length = (length+IO_SIZE-1) & ~(IO_SIZE-1);
180180
/*
181181
We must allocate some extra bytes for the end 0 and to be able to
182-
read big compressed blocks + 1 safety byte since uint3korr() in
183-
my_real_read() may actually read 4 bytes depending on build flags and
184-
platform.
182+
read big compressed blocks in my_real_read().
185183
*/
186184
if (!(buff= (uchar*) my_realloc((char*) net->buff, pkt_length +
187-
NET_HEADER_SIZE + COMP_HEADER_SIZE + 1,
185+
NET_HEADER_SIZE + COMP_HEADER_SIZE,
188186
MYF(MY_WME))))
189187
{
190188
/* @todo: 1 and 2 codes are identical. */
@@ -951,12 +949,11 @@ my_real_read(NET *net, size_t *complen)
951949
if (net->compress)
952950
{
953951
/*
954-
The following uint3korr() may read 4 bytes, so make sure we don't
955-
read unallocated or uninitialized memory. The right-hand expression
956-
must match the size of the buffer allocated in net_realloc().
952+
The right-hand expression must match the size of the buffer
953+
allocated in net_realloc().
957954
*/
958955
DBUG_ASSERT(net->where_b + NET_HEADER_SIZE + sizeof(uint32) <=
959-
net->max_packet + NET_HEADER_SIZE + COMP_HEADER_SIZE + 1);
956+
net->max_packet + NET_HEADER_SIZE + COMP_HEADER_SIZE);
960957
/*
961958
If the packet is compressed then complen > 0 and contains the
962959
number of bytes in the uncompressed packet

sql/records.cc

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000, 2010, Oracle and/or its affiliates. All rights reserved.
1+
/* Copyright (c) 2000, 2017, Oracle and/or its affiliates. All rights reserved.
22
33
This program is free software; you can redistribute it and/or modify
44
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)
589589
rec_cache_size= info->cache_records*info->reclength;
590590
info->rec_cache_size= info->cache_records*info->ref_length;
591591

592-
// We have to allocate one more byte to use uint3korr (see comments for it)
593592
if (info->cache_records <= 2 ||
594593
!(info->cache=(uchar*) my_malloc_lock(rec_cache_size+info->cache_records*
595-
info->struct_length+1,
594+
info->struct_length,
596595
MYF(0))))
597596
DBUG_RETURN(1);
598597
#ifdef HAVE_purify

0 commit comments

Comments
 (0)