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 [180.246.144.41]) by gnuweeb.org (Postfix) with ESMTPSA id CC89F809A8; Wed, 17 Aug 2022 01:09:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gnuweeb.org; s=default; t=1660698597; bh=Gry5J4MqQrxEsrTx5/ExYE6nMQbXrN1i79DUbY86NwE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RTjyv8YYhTI+wE0zVAJZRxu5mD+eZu9Z5CboxfgveXS9Vu8tcG9eEChAusV9T/wo3 DuX2yIsUbqDR2p/AyDjuClMri7lN8HdyNWyBtFx/ao+c6uTUr8CbLXhS3zDYuybWs2 bkzA9gHtKv3pkxL0m8RDD2ElAhRtHJ/gk+XwP6MYOHgjLVEpiP5FLRiK5NDRaqaNlF f9qYcyL/FQ9cilxTvIFnSpJSA9rEuyaNMh3V0v6r1XdKxRiRIpx+7TJ+1KyIgC08WA 7Hgiw5LzPR/03IgeNgiWSa3e1mNjmew1AfExwwPpTudlvwqHQ4jNbhAPZOg4TBwoTc /wnS4nt/7lD5Q== From: Ammar Faizi To: Alviro Iskandar Setiawan Cc: Ammar Faizi , GNU/Weeb Mailing List Subject: [PATCH ncns v1 1/2] chnet: node: Only take the pointer of buffer when available Date: Wed, 17 Aug 2022 08:09:41 +0700 Message-Id: <20220817010942.316631-2-ammarfaizi2@gnuweeb.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220817010942.316631-1-ammarfaizi2@gnuweeb.org> References: <20220817010942.316631-1-ammarfaizi2@gnuweeb.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit List-Id: The call to `ch->ch_.read_buf()` may be undefined behavior if the buffer hasn't been initialized. Don't touch this buffer and return null if it's not guaranteed to be initialized. Signed-off-by: Ammar Faizi --- chnet/chnet_node.cc | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/chnet/chnet_node.cc b/chnet/chnet_node.cc index 1491fd8..c89a745 100644 --- a/chnet/chnet_node.cc +++ b/chnet/chnet_node.cc @@ -267,20 +267,18 @@ static void CHN_NetSetURL(const Napi::CallbackInfo &info) ch->ch_.SetURL(url.c_str()); } -static Napi::String CHN_NetReadBuf(const Napi::CallbackInfo &info) +static Napi::Value CHN_NetReadBuf(const Napi::CallbackInfo &info) { Napi::Env env = info.Env(); - const char *buf; CHNetNode *ch; int ret; ch = (CHNetNode *)info.Data(); - buf = ch->ch_.read_buf(); ret = ch->ch_.read_ret(); if (ret > 0) - return Napi::String::New(env, buf, (size_t)ret); + return Napi::String::New(env, ch->ch_.read_buf(), (size_t)ret); - return Napi::String::New(env, ""); + return env.Null(); } static Napi::Number CHN_NetReadRet(const Napi::CallbackInfo &info) -- Ammar Faizi