Skip to content

Commit cd32758

Browse files
committed
Merge commit 'mysql-8.0' into mysql-trunk
Change-Id: I927b8dee0213d819884e946e709da2dde5eb2e04
2 parents b17b083 + 4e326c9 commit cd32758

File tree

3 files changed

+39
-0
lines changed

3 files changed

+39
-0
lines changed

storage/ndb/include/portlib/ndb_file.h

+1
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ class ndb_file
236236
int detect_direct_io_block_size_and_alignment();
237237
bool check_block_size_and_alignment(const void* buf, size_t count,
238238
ndb_off_t offset) const;
239+
bool check_is_regular_file() const;
239240
bool is_regular_file() const;
240241
int do_sync_after_write(size_t written_bytes);
241242

storage/ndb/include/portlib/ndb_socket_posix.h

+19
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include <sys/stat.h>
3636

3737
#include "ndb_config.h"
38+
#include "util/require.h"
3839

3940
#ifdef HAVE_POLL_H
4041
#include <poll.h>
@@ -109,21 +110,39 @@ int ndb_socket_nonblock(ndb_socket_t s, int enable)
109110
return 0;
110111
}
111112

113+
static inline
114+
bool ndb_is_socket(ndb_socket_t s)
115+
{
116+
#if defined(VM_TRACE) || !defined(NDEBUG) || defined(ERROR_INSERT)
117+
if (s.s == INVALID_SOCKET) return true;
118+
struct stat sb;
119+
if (fstat(s.s, &sb) == -1) return true;
120+
if((sb.st_mode & S_IFMT) == S_IFSOCK) return true;
121+
fprintf(stderr,"FATAL ERROR: %s: %u: Handle is not a socket: fd=%d file type=%o\n",__func__,__LINE__,s.s,sb.st_mode&S_IFMT);
122+
return false;
123+
#else
124+
return true;
125+
#endif
126+
}
127+
112128
static inline
113129
ssize_t ndb_recv(ndb_socket_t s, char* buf, size_t len, int flags)
114130
{
131+
require(ndb_is_socket(s));
115132
return recv(s.s, buf, len, flags);
116133
}
117134

118135
static inline
119136
ssize_t ndb_send(ndb_socket_t s, const char* buf, size_t len, int flags)
120137
{
138+
require(ndb_is_socket(s));
121139
return send(s.s, buf, len, flags);
122140
}
123141

124142
static inline
125143
ssize_t ndb_socket_writev(ndb_socket_t s, const struct iovec *iov, int iovcnt)
126144
{
145+
require(ndb_is_socket(s));
127146
return writev(s.s, iov, iovcnt);
128147
}
129148

storage/ndb/src/common/portlib/ndb_file_posix.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,23 @@ bool ndb_file::is_regular_file() const
6565
return false;
6666
}
6767

68+
bool ndb_file::check_is_regular_file() const
69+
{
70+
#if defined(VM_TRACE) || !defined(NDEBUG) || defined(ERROR_INSERT)
71+
if (!is_open()) return true;
72+
struct stat sb;
73+
if (fstat(m_handle, &sb) == -1) return true;
74+
if ((sb.st_mode & S_IFMT) == S_IFREG) return true;
75+
fprintf(stderr,"FATAL ERROR: %s: %u: Handle is not a regular file: fd=%d file type=%o\n",__func__,__LINE__,m_handle,sb.st_mode&S_IFMT);
76+
return false;
77+
#else
78+
return true;
79+
#endif
80+
}
81+
6882
int ndb_file::write_forward(const void* buf, ndb_file::size_t count)
6983
{
84+
require(check_is_regular_file());
7085
require(check_block_size_and_alignment(buf, count, get_pos()));
7186
int ret;
7287
do {
@@ -83,6 +98,7 @@ int ndb_file::write_forward(const void* buf, ndb_file::size_t count)
8398
int ndb_file::write_pos(const void* buf, ndb_file::size_t count,
8499
ndb_off_t offset)
85100
{
101+
require(check_is_regular_file());
86102
require(check_block_size_and_alignment(buf, count, offset));
87103
int ret;
88104
do {
@@ -98,6 +114,7 @@ int ndb_file::write_pos(const void* buf, ndb_file::size_t count,
98114

99115
int ndb_file::read_forward(void* buf, ndb_file::size_t count) const
100116
{
117+
require(check_is_regular_file());
101118
require(check_block_size_and_alignment(buf, count, 1));
102119
int ret;
103120
do {
@@ -107,6 +124,7 @@ int ndb_file::read_forward(void* buf, ndb_file::size_t count) const
107124
}
108125
int ndb_file::read_backward(void* buf, ndb_file::size_t count) const
109126
{
127+
require(check_is_regular_file());
110128
require(check_block_size_and_alignment(buf, count, 1));
111129
// Current pos must be within file.
112130
// Current pos - count must be within file.
@@ -146,6 +164,7 @@ int ndb_file::read_backward(void* buf, ndb_file::size_t count) const
146164
int ndb_file::read_pos(void* buf, ndb_file::size_t count,
147165
ndb_off_t offset) const
148166
{
167+
require(check_is_regular_file());
149168
require(check_block_size_and_alignment(buf, count, offset));
150169
int ret;
151170
do {

0 commit comments

Comments
 (0)