Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(165)

Unified Diff: extensions/browser/api/socket/socket_api.cc

Issue 608083002: Fix crash in deprecated Socket API. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « extensions/browser/api/socket/socket_api.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: extensions/browser/api/socket/socket_api.cc
diff --git a/extensions/browser/api/socket/socket_api.cc b/extensions/browser/api/socket/socket_api.cc
index f325d0a252b4434b7b674b766b704c325e5ec257..509b060a1b20d6ae02e13d67491bede13f8aa318 100644
--- a/extensions/browser/api/socket/socket_api.cc
+++ b/extensions/browser/api/socket/socket_api.cc
@@ -184,7 +184,8 @@ bool SocketDestroyFunction::Prepare() {
void SocketDestroyFunction::Work() { RemoveSocket(socket_id_); }
SocketConnectFunction::SocketConnectFunction()
- : socket_id_(0), hostname_(), port_(0), socket_(NULL) {}
+ : socket_id_(0), hostname_(), port_(0) {
+}
SocketConnectFunction::~SocketConnectFunction() {}
@@ -196,18 +197,18 @@ bool SocketConnectFunction::Prepare() {
}
void SocketConnectFunction::AsyncWorkStart() {
- socket_ = GetSocket(socket_id_);
- if (!socket_) {
+ Socket* socket = GetSocket(socket_id_);
+ if (!socket) {
error_ = kSocketNotFoundError;
SetResult(new base::FundamentalValue(-1));
AsyncWorkCompleted();
return;
}
- socket_->set_hostname(hostname_);
+ socket->set_hostname(hostname_);
SocketPermissionRequest::OperationType operation_type;
- switch (socket_->GetSocketType()) {
+ switch (socket->GetSocketType()) {
case Socket::TYPE_TCP:
operation_type = SocketPermissionRequest::TCP_CONNECT;
break;
@@ -242,9 +243,17 @@ void SocketConnectFunction::AfterDnsLookup(int lookup_result) {
}
void SocketConnectFunction::StartConnect() {
- socket_->Connect(resolved_address_,
- port_,
- base::Bind(&SocketConnectFunction::OnConnect, this));
+ Socket* socket = GetSocket(socket_id_);
+ if (!socket) {
+ error_ = kSocketNotFoundError;
+ SetResult(new base::FundamentalValue(-1));
+ AsyncWorkCompleted();
+ return;
+ }
+
+ socket->Connect(resolved_address_,
+ port_,
+ base::Bind(&SocketConnectFunction::OnConnect, this));
}
void SocketConnectFunction::OnConnect(int result) {
@@ -489,11 +498,8 @@ void SocketRecvFromFunction::OnCompleted(int bytes_read,
}
SocketSendToFunction::SocketSendToFunction()
- : socket_id_(0),
- io_buffer_(NULL),
- io_buffer_size_(0),
- port_(0),
- socket_(NULL) {}
+ : socket_id_(0), io_buffer_(NULL), io_buffer_size_(0), port_(0) {
+}
SocketSendToFunction::~SocketSendToFunction() {}
@@ -510,15 +516,15 @@ bool SocketSendToFunction::Prepare() {
}
void SocketSendToFunction::AsyncWorkStart() {
- socket_ = GetSocket(socket_id_);
- if (!socket_) {
+ Socket* socket = GetSocket(socket_id_);
+ if (!socket) {
error_ = kSocketNotFoundError;
SetResult(new base::FundamentalValue(-1));
AsyncWorkCompleted();
return;
}
- if (socket_->GetSocketType() == Socket::TYPE_UDP) {
+ if (socket->GetSocketType() == Socket::TYPE_UDP) {
SocketPermission::CheckParam param(
SocketPermissionRequest::UDP_SEND_TO, hostname_, port_);
if (!extension()->permissions_data()->CheckAPIPermissionWithParam(
@@ -543,11 +549,19 @@ void SocketSendToFunction::AfterDnsLookup(int lookup_result) {
}
void SocketSendToFunction::StartSendTo() {
- socket_->SendTo(io_buffer_,
- io_buffer_size_,
- resolved_address_,
- port_,
- base::Bind(&SocketSendToFunction::OnCompleted, this));
+ Socket* socket = GetSocket(socket_id_);
+ if (!socket) {
+ error_ = kSocketNotFoundError;
+ SetResult(new base::FundamentalValue(-1));
+ AsyncWorkCompleted();
+ return;
+ }
+
+ socket->SendTo(io_buffer_,
+ io_buffer_size_,
+ resolved_address_,
+ port_,
+ base::Bind(&SocketSendToFunction::OnCompleted, this));
}
void SocketSendToFunction::OnCompleted(int bytes_written) {
« no previous file with comments | « extensions/browser/api/socket/socket_api.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698