All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hongchen Zhang <zhanghongchen@loongson.cn>
To: Cyril Hrubis <chrubis@suse.cz>
Cc: ltp@lists.linux.it, Hongchen Zhang <zhanghongchen@loongson.cn>
Subject: [LTP] [PATCH] rpc01: fix variable not initialized
Date: Mon,  4 Jul 2022 20:17:49 +0800	[thread overview]
Message-ID: <1656937069-17098-1-git-send-email-zhanghongchen@loongson.cn> (raw)

when error occurred in function callrpc/clnt_call, return_buffer may
be leaved not initialized.So initialize return_buffer to NULL,and
retrieve the return_buffer->data when return_buffer is really assigned.

Signed-off-by: Hongchen Zhang <zhanghongchen@loongson.cn>
---
 testcases/network/rpc/basic_tests/rpc01/rpc1.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/testcases/network/rpc/basic_tests/rpc01/rpc1.c b/testcases/network/rpc/basic_tests/rpc01/rpc1.c
index bc9f35b..5691c06 100644
--- a/testcases/network/rpc/basic_tests/rpc01/rpc1.c
+++ b/testcases/network/rpc/basic_tests/rpc01/rpc1.c
@@ -24,7 +24,7 @@ void usage_error(char *program_name);
 int main(int argc, char *argv[])
 {
 	struct hostent *hp;
-	struct data buffer, *return_buffer;
+	struct data buffer, *return_buffer = NULL;
 	int i, n, rc;
 	FILE *fp;
 	struct stat stat_buffer;
@@ -128,7 +128,8 @@ int main(int argc, char *argv[])
 	rc = callrpc(server, program, version, 1, (xdrproc_t)xdr_send_data,
 			(char *)&buffer, (xdrproc_t)xdr_receive_data,
 			(char *)&return_buffer);
-	do_compare(rc, "callrpc", &buffer, return_buffer->data);
+	do_compare(rc, "callrpc", &buffer,
+				return_buffer ? return_buffer->data : NULL);
 
 	server_sin.sin_port = 0;
 	sock = RPC_ANYSOCK;
@@ -145,7 +146,8 @@ int main(int argc, char *argv[])
 				(char *)&buffer, (xdrproc_t)xdr_receive_data,
 				(char *)&return_buffer, timeout);
 	clnt_destroy(clnt);
-	do_compare(rc, "udp transport", &buffer, return_buffer->data);
+	do_compare(rc, "udp transport", &buffer,
+				return_buffer ? return_buffer->data : NULL);
 
 	server_sin.sin_port = 0;
 	sock = RPC_ANYSOCK;
@@ -160,7 +162,8 @@ int main(int argc, char *argv[])
 				(char *)&buffer, (xdrproc_t)xdr_receive_data,
 				(char *)&return_buffer, timeout);
 	clnt_destroy(clnt);
-	do_compare(rc, "tcp transport", &buffer, return_buffer->data);
+	do_compare(rc, "tcp transport", &buffer,
+				return_buffer ? return_buffer->data : NULL);
 
 	exit(0);
 }
-- 
1.8.3.1


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

             reply	other threads:[~2022-07-04 12:18 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-04 12:17 Hongchen Zhang [this message]
2022-07-11  6:09 ` [LTP] [PATCH] rpc01: fix variable not initialized Petr Vorel
2022-07-12  6:43   ` [LTP] [PATCH v2] " Hongchen Zhang
2022-10-10 13:23     ` Richard Palethorpe
2022-10-10 14:40       ` Petr Vorel
2022-10-11  8:36         ` Richard Palethorpe
2022-10-11  8:50           ` Petr Vorel
2022-07-12  6:46   ` Hongchen Zhang
2022-07-12  7:01   ` [LTP] [PATCH] " Hongchen Zhang
  -- strict thread matches above, loose matches on Subject: below --
2022-07-04 12:08 Hongchen Zhang

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 \
    --in-reply-to=1656937069-17098-1-git-send-email-zhanghongchen@loongson.cn \
    --to=zhanghongchen@loongson.cn \
    --cc=chrubis@suse.cz \
    --cc=ltp@lists.linux.it \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.