GNU/Weeb Mailing List <[email protected]>
 help / color / mirror / Atom feed
From: Ammar Faizi <[email protected]>
To: Alviro Iskandar Setiawan <[email protected]>
Cc: Ammar Faizi <[email protected]>,
	GNU/Weeb Mailing List <[email protected]>
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	[thread overview]
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>

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 <[email protected]>
---
 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


  reply	other threads:[~2022-08-17  1:09 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-17  1:09 [PATCH ncns v1 0/2] ncns fixes Ammar Faizi
2022-08-17  1:09 ` Ammar Faizi [this message]
2022-08-17  1:09 ` [PATCH ncns v1 2/2] chnet: node: Fix unused variable warning Ammar Faizi
2022-08-17  1:14 ` [PATCH ncns v1 0/2] ncns fixes Alviro Iskandar Setiawan

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] \
    /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