Skip to contentSkip to conversation

clnt_create: Determine the return value of clnt_create()

PATCH In review Ma Xinjian via ltp 2 participants 2 messages Oct 22, 2024

lore
Share & tools
lore
#0 lore raw

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
index 98793c640..8578d943c 100644
@@ -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
index 58f55d71e..c5780d629 100644
@@ -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
index f10f15d9b..85c0d5fe6 100644
@@ -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
index 9fef30f6b..ba5324c18 100644
@@ -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
index 0aaa50c27..03756cf7e 100644
@@ -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
index 489c6c8b6..a881a4a09 100644
@@ -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
index 74c6201d3..ddf2ec441 100644
@@ -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
index 65e68dae6..a85e87787 100644
@@ -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
index 1e74c39a3..728f35a97 100644
@@ -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
index fc10f9e04..de4734579 100644
@@ -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
index 50232a91a..34b1b2bf9 100644
@@ -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
index 3f9ea9142..4483fb6ab 100644
@@ -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
index 8fa54d9f0..9dfc65431 100644
@@ -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
index 2a45f5055..17546fe0a 100644
@@ -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
index 563b11a36..a9dd71b5d 100644
@@ -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
index 0b37585ec..91d087141 100644
@@ -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
index 3616d652c..10de96e10 100644
@@ -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
index 9bbce26af..d0505e623 100644
@@ -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
index 029d158ff..81bf37e36 100644
@@ -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
index a1b16416a..c3ec08887 100644
@@ -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
index 445ecfd32..8a8cdf238 100644
@@ -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
index e363e00b9..a97bbfa17 100644
@@ -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
index eaca14747..6a9aae6c0 100644
@@ -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
index 43df4d95f..8723ca8c8 100644
@@ -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
#1 lore raw

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 executing clnt_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.c

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;
+		}
 	}

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