From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on gnuweeb.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=5.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NO_DNS_FOR_FROM,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.6 Received: from localhost.localdomain (unknown [182.253.183.240]) by gnuweeb.org (Postfix) with ESMTPSA id EB83F7E245; Thu, 17 Nov 2022 17:27:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1668706061; bh=EEQU/oXo76GuTpP+qXRHtvmmQZMQY6gjqEzRrvinmkw=; h=From:To:Cc:Subject:Date:From; b=TS3hyo32gKak1omT0S20LjAi8BbG/XPugjq3MbBq29LVwVVD1sEygjKcEQU2begWT jaYy3l1vPcHZs03evreM/VosVD5keVTJZlcjXTquHjFi7qvR4uDGWuC1cxi2VVFSOa Ol0LQLEZpbIUBM3zWTnzl7G/MhCdjHy2eEfLaMUI2nVSKw9nmkUy9m6ntDMbXUCDr8 X/Iw7rAN8pEhymE2JTilk30gLz+ZBuiHNwNbX/T83p2Ezs4dzrRTtJdOt+5x0Yf6IL lvFBzN9MnMTjCJkDpmhF4RR9WrWz9DHIbss7x7zbou8ho/dFFqVUaf7QqHaX2kJc53 DOjJoZ9njyJYQ== From: Ammar Faizi To: Gilang Fachrezi Cc: Alviro Iskandar Setiawan , Muhammad Rizki , Dina Maulina , Kernel Team , Network Integration Team , GNU/Weeb Mailing List , Ammar Faizi Subject: Fix data corruption bug Date: Fri, 18 Nov 2022 00:27:29 +0700 Message-Id: <20221117172729.2302627-1-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: From: Ammar Faizi 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 --- 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(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