clnt_create: Determine the return value of clnt_create()
PATCH 1/1 clnt_create: Determine the return value of clnt_create()
Determine the return value of clnt_create() to avoid segmentation fault when executing clnt_destroy() when the return value of create is NULL.
--- .../rpc/rpc_createdestroy_clnt_create/rpc_clnt_create.c | 7 +++++++ .../rpc_createdestroy_clnt_create/rpc_clnt_create_stress.c | 6 ++++++ .../rpc/rpc_createdestroy_clnt_destroy/rpc_clnt_destroy.c | 7 +++++++ .../rpc_clnt_destroy_stress.c | 5 +++++ .../rpc/rpc_err_clnt_pcreateerror/rpc_clnt_pcreateerror.c | 7 +++++++ .../rpc_suite/rpc/rpc_err_clnt_perrno/rpc_clnt_perrno.c | 7 +++++++ .../rpc_suite/rpc/rpc_err_clnt_perror/rpc_clnt_perror.c | 7 +++++++ .../rpc_err_clnt_spcreateerror/rpc_clnt_spcreateerror.c | 7 +++++++ .../rpc_suite/rpc/rpc_err_clnt_sperrno/rpc_clnt_sperrno.c | 7 +++++++ .../rpc_suite/rpc/rpc_err_clnt_sperror/rpc_clnt_sperror.c | 7 +++++++ .../rpc_suite/rpc/rpc_err_svcerr_auth/rpc_svcerr_auth.c | 7 +++++++ .../rpc/rpc_err_svcerr_noproc/rpc_svcerr_noproc.c | 7 +++++++ .../rpc/rpc_err_svcerr_progvers/rpc_svcerr_progvers.c | 7 +++++++ .../rpc/rpc_err_svcerr_systemerr/rpc_svcerr_systemerr.c | 7 +++++++ .../rpc/rpc_err_svcerr_weakauth/rpc_svcerr_weakauth.c | 7 +++++++ .../rpc/rpc_stdcall_clnt_control/rpc_clnt_control.c | 7 +++++++ .../rpc_stdcall_clnt_control/rpc_clnt_control_dataint.c | 7 +++++++ .../rpc/rpc_stdcall_clnt_geterr/rpc_clnt_geterr.c | 7 +++++++ .../tirpc_err_clnt_pcreateerror/tirpc_clnt_pcreateerror.c | 7 +++++++ .../tirpc/tirpc_err_clnt_perrno/tirpc_clnt_perrno.c | 7 +++++++ .../tirpc/tirpc_err_clnt_perror/tirpc_clnt_perror.c | 7 +++++++ .../tirpc_err_clnt_perror/tirpc_clnt_perror_complex.c | 7 +++++++ .../tirpc/tirpc_toplevel_clnt_create/tirpc_clnt_create.c | 7 +++++++ .../tirpc_clnt_create_timed.c | 7 +++++++ 24 files changed, 165 insertions(+)
testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_createdestroy_clnt_create/rpc_clnt_create.c +7 -0
@@ -52,6 +52,13 @@ int main(int argn, char *argc[])//First of all, create a client clnt =clnt_create (argc[1 ], progNum,VERSNUM , proto); +if (clnt ==NULL ) { +clnt_pcreateerror ("err" ); +printf ("%d\n" , rpc_createerr.cf_stat); + +return 1 ; + } +if (run_mode ==1 ) {printf ("CLIENT : %p\n" , clnt); }
testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_createdestroy_clnt_create/rpc_clnt_create_stress.c +6 -0
@@ -59,6 +59,12 @@ int main(int argn, char *argc[])if (clnt !=NULL ) nbOk++; +else { +clnt_pcreateerror ("err" ); +printf ("%d\n" , rpc_createerr.cf_stat); + +return 1 ; + } }if (run_mode ==1 ) {
testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_createdestroy_clnt_destroy/rpc_clnt_destroy.c +7 -0
@@ -48,6 +48,13 @@ int main(int argn, char *argc[])//First of all, create a client clnt =clnt_create (argc[1 ], progNum,VERSNUM , proto); +if (clnt ==NULL ) { +clnt_pcreateerror ("err" ); +printf ("%d\n" , rpc_createerr.cf_stat); + +return 1 ; + } +//Then call destroy macro clnt_destroy (clnt);
testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_createdestroy_clnt_destroy/rpc_clnt_destroy_stress.c +5 -0
@@ -56,6 +56,11 @@ int main(int argn, char *argc[])//First of all, create a client for (i =0 ; i < nbCall; i++) { clnt =clnt_create (argc[1 ], progNum,VERSNUM , proto); +if (clnt ==NULL ) { +clnt_pcreateerror ("err" ); +printf ("%d\n" , rpc_createerr.cf_stat); +return 1 ; + }clnt_destroy (clnt); nbOk++; }
testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_err_clnt_pcreateerror/rpc_clnt_pcreateerror.c +7 -0
@@ -49,6 +49,13 @@ int main(int argn, char *argc[]) clnt =clnt_create (argc[1 ], progNum,VERSNUM , nettype); +if (clnt ==NULL ) { +clnt_pcreateerror ("err" ); +printf ("%d\n" , rpc_createerr.cf_stat); + +return 1 ; + } +clnt_pcreateerror ("#SUCCESS" );//If we are here, test has passed
testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_err_clnt_perrno/rpc_clnt_perrno.c +7 -0
@@ -65,6 +65,13 @@ int main(int argn, char *argc[])//First of all, create client using top level API clnt =clnt_create (argc[1 ], progNum,VERSNUM , nettype); +if (clnt ==NULL ) { +clnt_pcreateerror ("err" ); +printf ("%d\n" , rpc_createerr.cf_stat); + +return 1 ; + } +//Then call remote procedure rslt = clnt_call((CLIENT *) clnt, PROCNUM, (xdrproc_t) xdr_int, (char *)&recVar, // xdr_in (xdrproc_t) xdr_int, (char *)&recVar, // xdr_out
testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_err_clnt_perror/rpc_clnt_perror.c +7 -0
@@ -65,6 +65,13 @@ int main(int argn, char *argc[])//First of all, create client using top level API clnt =clnt_create (argc[1 ], progNum,VERSNUM , nettype); +if (clnt ==NULL ) { +clnt_pcreateerror ("err" ); +printf ("%d\n" , rpc_createerr.cf_stat); + +return 1 ; + } +//Then call remote procedure rslt = clnt_call((CLIENT *) clnt, PROCNUM, (xdrproc_t) xdr_void, NULL, // xdr_in (xdrproc_t) xdr_int, (char *)&recVar, // xdr_out
testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_err_clnt_spcreateerror/rpc_clnt_spcreateerror.c +7 -0
@@ -50,6 +50,13 @@ int main(int argn, char *argc[]) clnt =clnt_create (argc[1 ], progNum,VERSNUM , nettype); +if (clnt ==NULL ) { +clnt_pcreateerror ("err" ); +printf ("%d\n" , rpc_createerr.cf_stat); + +return 1 ; + } + rslt =clnt_spcreateerror ("#SUCCESS" );//If we are here, test has passed
testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_err_clnt_sperrno/rpc_clnt_sperrno.c +7 -0
@@ -66,6 +66,13 @@ int main(int argn, char *argc[])//First of all, create client using top level API clnt =clnt_create (argc[1 ], progNum,VERSNUM , nettype); +if (clnt ==NULL ) { +clnt_pcreateerror ("err" ); +printf ("%d\n" , rpc_createerr.cf_stat); + +return 1 ; + } +//Then call remote procedure rslt = clnt_call((CLIENT *) clnt, PROCNUM, (xdrproc_t) xdr_int, (char *)&recVar, // xdr_in (xdrproc_t) xdr_int, (char *)&recVar, // xdr_out
testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_err_clnt_sperror/rpc_clnt_sperror.c +7 -0
@@ -66,6 +66,13 @@ int main(int argn, char *argc[])//First of all, create client using top level API clnt =clnt_create (argc[1 ], progNum,VERSNUM , nettype); +if (clnt ==NULL ) { +clnt_pcreateerror ("err" ); +printf ("%d\n" , rpc_createerr.cf_stat); + +return 1 ; + } +//Then call remote procedure rslt = clnt_call((CLIENT *) clnt, PROCNUM, (xdrproc_t) xdr_void, NULL, // xdr_in (xdrproc_t) xdr_int, (char *)&recVar, // xdr_out
testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_err_svcerr_auth/rpc_svcerr_auth.c +7 -0
@@ -62,6 +62,13 @@ int main(int argn, char *argc[]) client =clnt_create (argc[1 ], progNum,VERSNUM , nettype);/* Call AuthErr RP */ +if (client ==NULL ) { +clnt_pcreateerror ("err" ); +printf ("%d\n" , rpc_createerr.cf_stat); + +return 1 ; + } + cs =clnt_call (client,PROCNUM , (xdrproc_t ) xdr_int, (char *)&var_snd, (xdrproc_t ) xdr_int, (char *)&var_snd, tv);
testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_err_svcerr_noproc/rpc_svcerr_noproc.c +7 -0
@@ -65,6 +65,13 @@ int main(int argn, char *argc[]) client =clnt_create (argc[1 ], progNum,VERSNUM , nettype); +if (client ==NULL ) { +clnt_pcreateerror ("err" ); +printf ("%d\n" , rpc_createerr.cf_stat); + +return 1 ; + } +//Then call remote procedure cs = clnt_call((CLIENT *) client, PROCNUM, (xdrproc_t) xdr_int, (char *)&var_snd, // xdr_in (xdrproc_t) xdr_int, (char *)&var_snd, // xdr_out
testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_err_svcerr_progvers/rpc_svcerr_progvers.c +7 -0
@@ -62,6 +62,13 @@ int main(int argn, char *argc[]) client =clnt_create (argc[1 ], progNum,VERSNUM , nettype);/* Call wrong version RP */ +if (client ==NULL ) { +clnt_pcreateerror ("err" ); +printf ("%d\n" , rpc_createerr.cf_stat); + +return 1 ; + } + cs =clnt_call (client,PROCNUM , (xdrproc_t ) xdr_int, (char *)&var_snd, (xdrproc_t ) xdr_int, (char *)&var_snd, tv);
testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_err_svcerr_systemerr/rpc_svcerr_systemerr.c +7 -0
@@ -62,6 +62,13 @@ int main(int argn, char *argc[]) client =clnt_create (argc[1 ], progNum,VERSNUM , nettype);/* Call SysErr RP */ +if (client ==NULL ) { +clnt_pcreateerror ("err" ); +printf ("%d\n" , rpc_createerr.cf_stat); + +return 1 ; + } + cs =clnt_call (client,PROCNUM , (xdrproc_t ) xdr_int, (char *)&var_snd, (xdrproc_t ) xdr_int, (char *)&var_snd, tv);
testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_err_svcerr_weakauth/rpc_svcerr_weakauth.c +7 -0
@@ -62,6 +62,13 @@ int main(int argn, char *argc[]) client =clnt_create (argc[1 ], progNum,VERSNUM , nettype);/* Call WeakAuthErr RP */ +if (client ==NULL ) { +clnt_pcreateerror ("err" ); +printf ("%d\n" , rpc_createerr.cf_stat); + +return 1 ; + } + cs =clnt_call (client,PROCNUM , (xdrproc_t ) xdr_int, (char *)&var_snd, (xdrproc_t ) xdr_int, (char *)&var_snd, tv);
testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_stdcall_clnt_control/rpc_clnt_control.c +7 -0
@@ -53,6 +53,13 @@ int main(int argn, char *argc[])//First of all, create a client clnt =clnt_create (argc[1 ], progNum,VERSNUM , proto); +if (clnt ==NULL ) { +clnt_pcreateerror ("err" ); +printf ("%d\n" , rpc_createerr.cf_stat); + +return 1 ; + } +if (run_mode ==1 ) {printf ("CLIENT : %p\n" , clnt); }
testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_stdcall_clnt_control/rpc_clnt_control_dataint.c +7 -0
@@ -54,6 +54,13 @@ int main(int argn, char *argc[])//First of all, create a client clnt =clnt_create (argc[1 ], progNum,VERSNUM , proto); +if (clnt ==NULL ) { +clnt_pcreateerror ("err" ); +printf ("%d\n" , rpc_createerr.cf_stat); + +return 1 ; + } +if (run_mode) {printf ("CLIENT : %p\n" , clnt); }
testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_stdcall_clnt_geterr/rpc_clnt_geterr.c +7 -0
@@ -53,6 +53,13 @@ int main(int argn, char *argc[])//First of all, create a client clnt =clnt_create (argc[1 ], progNum,VERSNUM , proto); +if (clnt ==NULL ) { +clnt_pcreateerror ("err" ); +printf ("%d\n" , rpc_createerr.cf_stat); + +return 1 ; + } +if (run_mode ==1 ) {printf ("CLIENT : %p\n" , clnt); }
testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/tirpc/tirpc_err_clnt_pcreateerror/tirpc_clnt_pcreateerror.c +7 -0
@@ -50,6 +50,13 @@ int main(int argn, char *argc[]) clnt =clnt_create (argc[1 ], progNum,VERSNUM , nettype); +if (clnt ==NULL ) { +clnt_pcreateerror ("err" ); +printf ("%d\n" , rpc_createerr.cf_stat); + +return 1 ; + } +clnt_pcreateerror ("#SUCCESS" );//If we are here, test has passed
testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/tirpc/tirpc_err_clnt_perrno/tirpc_clnt_perrno.c +7 -0
@@ -65,6 +65,13 @@ int main(int argn, char *argc[])//First of all, create client using top level API clnt =clnt_create (argc[1 ], progNum,VERSNUM , nettype); +if (clnt ==NULL ) { +clnt_pcreateerror ("err" ); +printf ("%d\n" , rpc_createerr.cf_stat); + +return 1 ; + } +//Then call remote procedure rslt = clnt_call((CLIENT *) clnt, PROCNUM, (xdrproc_t) xdr_void, NULL, // xdr_in (xdrproc_t) xdr_int, (char *)&recVar, // xdr_out
testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/tirpc/tirpc_err_clnt_perror/tirpc_clnt_perror.c +7 -0
@@ -65,6 +65,13 @@ int main(int argn, char *argc[])//First of all, create client using top level API clnt =clnt_create (argc[1 ], progNum,VERSNUM , nettype); +if (clnt ==NULL ) { +clnt_pcreateerror ("err" ); +printf ("%d\n" , rpc_createerr.cf_stat); + +return 1 ; + } +//Then call remote procedure rslt = clnt_call((CLIENT *) clnt, PROCNUM, (xdrproc_t) xdr_void, NULL, // xdr_in (xdrproc_t) xdr_int, (char *)&recVar, // xdr_out
testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/tirpc/tirpc_err_clnt_perror/tirpc_clnt_perror_complex.c +7 -0
@@ -64,6 +64,13 @@ int main(int argn, char *argc[]) total_timeout.tv_usec =1 ;/**/ clnt =clnt_create (argc[1 ], progNum,VERSNUM , nettype); +if (clnt ==NULL ) { +clnt_pcreateerror ("err" ); +printf ("%d\n" , rpc_createerr.cf_stat); + +return 1 ; + } +//Multiple test case rslt = rpc_call(argc[1], progNum, VERSNUM, PROCNUM, (xdrproc_t) xdr_int, (char *)&sndVar,
testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/tirpc/tirpc_toplevel_clnt_create/tirpc_clnt_create.c +7 -0
@@ -57,6 +57,13 @@ int main(int argn, char *argc[]) } clnt =clnt_create (argc[1 ], progNum,VERSNUM , nettype); +if (clnt ==NULL ) { +clnt_pcreateerror ("err" ); +printf ("%d\n" , rpc_createerr.cf_stat); + +return 1 ; + } +if (run_mode ==1 ) {printf ("Client after creation : %p\n" , clnt); }
testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/tirpc/tirpc_toplevel_clnt_create_timed/tirpc_clnt_create_timed.c +7 -0
@@ -62,6 +62,13 @@ int main(int argn, char *argc[]) clnt =clnt_create_timed (argc[1 ], progNum,VERSNUM , nettype, &tv); +if (clnt ==NULL ) { +clnt_pcreateerror ("err" ); +printf ("%d\n" , rpc_createerr.cf_stat); + +return 1 ; + } +if (run_mode ==1 ) {printf ("Client after creation : %p\n" , clnt); }
Signature · 5 lines
2.42.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Ma,
Thanks a lot, merged!
BTW I see some of the tests already had error control and they just printed 1 instead of rpc_createerr.cf_stat (rpc_clnt_call_dataint.c). Some other report 5 (e.g. rpc_clnt_call_performance.c).
Quoted 2 lines
Determine the return value of
clnt_create()to avoid segmentation fault when executingclnt_destroy()when the return value of create is NULL.
...
testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_createdestroy_clnt_create/rpc_clnt_create_stress.c int main(int argn, char *argc[]) · line 68
Quoted 12 lines
+++
b/testcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_createdestroy_clnt_create/rpc_clnt_create_stress.ctestcases/network/rpc/rpc-tirpc/tests_pack/rpc_suite/rpc/rpc_createdestroy_clnt_create/rpc_clnt_create_stress.c +6
-0@@ -59,6 +59,12 @@ int main(int argn, char *argc[])if (clnt !=NULL ) nbOk++; +else { +clnt_pcreateerror ("err" ); +printf ("%d\n" , rpc_createerr.cf_stat); + +return 1 ; + } }
I reversed the condition of the check (more readable code):
if (clnt == NULL) {
clnt_pcreateerror("err");
printf("%d\n", rpc_createerr.cf_stat);
return 1;
}
nbOk++;The testsuite contains a lot of duplicity and useless code. It could be rewritten to use simple macro to remove most of the redundancy.
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp