[LTP] [PATCH] rpc01: fix variable not initialized
Hongchen Zhang
zhanghongchen@loongson.cn
Tue Jul 12 09:01:28 CEST 2022
On 2022/7/11 下午2:09, Petr Vorel wrote:
> Hi all,
>
> [ Cc Steve and libtirpc-devel ML ]
>
>> 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.
>
> Shouldn't be rc used for verification?
>
> man callrpc(3):
> int callrpc(...);
> ...
> This routine returns zero if it succeeds, or the value of enum clnt_stat cast to
> an integer if it fails. The routine clnt_perrno() is handy for translating
> failure statuses into messages.
>
> Kind regards,
> Petr
>
>> 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);
>> }
Hi Petr,
I have modified as you said and have send another patch,the new
method is to change the parameter passed to do_compare, please check again.
Best Regards,
Hongchen
More information about the ltp
mailing list