Skip to content

Commit

Permalink
clnt_create: Determine the return value of clnt_create()
Browse files Browse the repository at this point in the history
Determine the return value of clnt_create() to avoid segmentation fault
when executing clnt_destroy() when the return value of create is NULL.

Link: https://lore.kernel.org/ltp/[email protected]/
Reviewed-by: Petr Vorel <[email protected]>
Signed-off-by: Ma Xinjian <[email protected]>
Signed-off-by: Petr Vorel <[email protected]>
  • Loading branch information
MaXinjian authored and pevik committed Oct 22, 2024
1 parent 1a32f6b commit 18c5ce6
Show file tree
Hide file tree
Showing 24 changed files with 167 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,14 @@ int main(int argn, char *argc[])
for (i = 0; i < nbCall; i++) {
clnt = clnt_create(argc[1], progNum, VERSNUM, proto);

if (clnt != NULL)
nbOk++;
if (clnt == NULL) {
clnt_pcreateerror("err");
printf("%d\n", rpc_createerr.cf_stat);

return 1;
}

nbOk++;
}

if (run_mode == 1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit 18c5ce6

Please sign in to comment.