[LTP] [PATCH v2] rpc01: fix variable not initialized

Petr Vorel pvorel@suse.cz
Mon Oct 10 16:40:44 CEST 2022


Hi Richie,


> Hello,

> Looks OK to me, Petr?

> Acked-by: Richard Palethorpe <rpalethorpe@suse.com>

I replied at ML at v1 [1] with a question to use rc for verification.
I'm not sure whether it was me who marked the question as superseded.

@Hongchen you sent v1 twice, v2 twice. Duplicate send without your reply does
not speedup things. Please next time reply with ping (but if you don't reply to
the question, ball is on your side).

Kind regards,
Petr

[1] https://lore.kernel.org/ltp/Ysu+mbkO8eUP4A2+@pevik/
[2] https://patchwork.ozlabs.org/project/ltp/list/?submitter=84160&state=*

> Hongchen Zhang <zhanghongchen@loongson.cn> writes:

> > 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..6b8619d 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