[LTP] [PATCH] rpc01: fix variable not initialized
Hongchen Zhang
zhanghongchen@loongson.cn
Mon Jul 4 14:17:49 CEST 2022
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
More information about the ltp
mailing list