[LTP] [PATCH v2] rpc01: fix variable not initialized
Hongchen Zhang
zhanghongchen@loongson.cn
Tue Jul 12 08:46:40 CEST 2022
when error occurred in function callrpc/clnt_call, return_buffer may
be leaved not initialized.
As Petr said, we should check the return value before retrieve the
return_buffer->data. Change do_compare's parameter from char * to
struct data * to fix it.
Signed-off-by: Hongchen Zhang <zhanghongchen@loongson.cn>
---
testcases/network/rpc/basic_tests/rpc01/rpc1.c | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/testcases/network/rpc/basic_tests/rpc01/rpc1.c b/testcases/network/rpc/basic_tests/rpc01/rpc1.c
index bc9f35b..8ef0e4d 100644
--- a/testcases/network/rpc/basic_tests/rpc01/rpc1.c
+++ b/testcases/network/rpc/basic_tests/rpc01/rpc1.c
@@ -18,7 +18,8 @@ char *file_name = NULL;
char host_name[100];
long host_address;
-void do_compare(int, char *, struct data *, char *);
+void do_compare(int rpc_rc, char *msg, struct data *buffer,
+ struct data *ret_buffer);
void usage_error(char *program_name);
int main(int argc, char *argv[])
@@ -128,7 +129,7 @@ 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);
server_sin.sin_port = 0;
sock = RPC_ANYSOCK;
@@ -145,7 +146,7 @@ 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);
server_sin.sin_port = 0;
sock = RPC_ANYSOCK;
@@ -160,12 +161,13 @@ 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);
exit(0);
}
-void do_compare(int rpc_rc, char *msg, struct data *buffer, char *ret_data)
+void do_compare(int rpc_rc, char *msg, struct data *buffer,
+ struct data *ret_buffer)
{
int rc;
@@ -175,7 +177,7 @@ void do_compare(int rpc_rc, char *msg, struct data *buffer, char *ret_data)
printf("\n");
exit(1);
}
- rc = memcmp(buffer->data, ret_data, buffer->data_length);
+ rc = memcmp(buffer->data, ret_buffer->data, buffer->data_length);
if (rc) {
printf("Data compare for %s returned %d\n", msg, rc);
exit(1);
--
1.8.3.1
More information about the ltp
mailing list