public inbox for [email protected]
 help / color / mirror / Atom feed
* Fix data corruption bug
@ 2022-11-17 17:27 Ammar Faizi
  2022-11-18  2:30 ` Alviro Iskandar Setiawan
  0 siblings, 1 reply; 3+ messages in thread
From: Ammar Faizi @ 2022-11-17 17:27 UTC (permalink / raw)
  To: Gilang Fachrezi
  Cc: Alviro Iskandar Setiawan, Muhammad Rizki, Dina Maulina,
	Kernel Team, Network Integration Team, GNU/Weeb Mailing List,
	Ammar Faizi

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


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-11-18 16:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-17 17:27 Fix data corruption bug Ammar Faizi
2022-11-18  2:30 ` Alviro Iskandar Setiawan
2022-11-18 16:09   ` Kyoko Senpai

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox