Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

common/admin-socket: fix potential buffer overflow #12518

Merged
merged 2 commits into from Dec 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/common/admin_socket.cc
Expand Up @@ -315,7 +315,7 @@ bool AdminSocket::do_accept()
}

char cmd[1024];
int pos = 0;
unsigned pos = 0;
string c;
while (1) {
int ret = safe_read(connection_fd, &cmd[pos], 1);
Expand Down Expand Up @@ -353,7 +353,11 @@ bool AdminSocket::do_accept()
break;
}
}
pos++;
if (++pos >= sizeof(cmd)) {
lderr(m_cct) << "AdminSocket: error reading request too long" << dendl;
VOID_TEMP_FAILURE_RETRY(close(connection_fd));
return false;
}
}

bool rval = false;
Expand Down
14 changes: 14 additions & 0 deletions src/test/admin_socket.cc
Expand Up @@ -105,6 +105,20 @@ TEST(AdminSocket, SendNoOp) {
ASSERT_EQ(true, asoct.shutdown());
}

TEST(AdminSocket, SendTooLongRequest) {
std::unique_ptr<AdminSocket>
asokc(new AdminSocket(g_ceph_context));
AdminSocketTest asoct(asokc.get());
ASSERT_EQ(true, asoct.shutdown());
ASSERT_EQ(true, asoct.init(get_rand_socket_path()));
AdminSocketClient client(get_rand_socket_path());
string version;
string request(16384, 'a');
//if admin_socket cannot handle it, segfault will happened.
ASSERT_NE("", client.do_request(request, &version));
ASSERT_EQ(true, asoct.shutdown());
}

class MyTest : public AdminSocketHook {
bool call(std::string command, cmdmap_t& cmdmap, std::string format, bufferlist& result) {
std::vector<std::string> args;
Expand Down