public inbox for [email protected]
 help / color / mirror / Atom feed
From: Ammar Faizi <[email protected]>
To: Gilang Fachrezi <[email protected]>
Cc: Alviro Iskandar Setiawan <[email protected]>,
	Muhammad Rizki <[email protected]>,
	Dina Maulina <[email protected]>,
	Kernel Team <[email protected]>,
	Network Integration Team <[email protected]>,
	GNU/Weeb Mailing List <[email protected]>,
	Ammar Faizi <[email protected]>
Subject: Fix data corruption bug
Date: Fri, 18 Nov 2022 00:27:29 +0700	[thread overview]
Message-ID: <[email protected]> (raw)

From: Ammar Faizi <[email protected]>
Subject: [PATCH] chnet: Fix data corruption when a read operation is pending

When a read operation is pending, the @read_ret_ variable has to be
set to -EINPROGRESS. The current CHNetDelegate::__Read() method
doesn't do that. This situation makes the caller abort the request
because it doesn't see -EINPROGRESS from the return value. This bug
is reproducible on a slow network connection where __Read()
operation often results in a pending state.

This bug is introduced in commit 77bbcc903899 ("chnet: Completely
refactor again").

Fixes: 77bbcc903899 ("chnet: Completely refactor again")
Signed-off-by: Ammar Faizi <[email protected]>
---
 chnet/chnet.cc | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/chnet/chnet.cc b/chnet/chnet.cc
index cd27810..fdbbdc6 100644
--- a/chnet/chnet.cc
+++ b/chnet/chnet.cc
@@ -713,9 +713,14 @@ int CHNetDelegate::__Read(int size)
 
 	read_buf_ = base::MakeRefCounted<net::IOBufferWithSize>(size);
 	ret = url_req_->Read(read_buf_.get(), size);
-	read_ret_.store(ret, std::memory_order_release);
 
-	if (ret != net::ERR_IO_PENDING && callback_.on_read_completed_)
+	if (ret == net::ERR_IO_PENDING) {
+		read_ret_.store(-EINPROGRESS, std::memory_order_release);
+		return ret;
+	}
+
+	read_ret_.store(ret, std::memory_order_release);
+	if (callback_.on_read_completed_)
 		std::move(callback_.on_read_completed_)(url_req_.get(), ret);
 
 	return ret;
-- 
Ammar Faizi


             reply	other threads:[~2022-11-17 17:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-17 17:27 Ammar Faizi [this message]
2022-11-18  2:30 ` Fix data corruption bug Alviro Iskandar Setiawan
2022-11-18 16:09   ` Kyoko Senpai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    [email protected] \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox