rpc: don't malloc server_name for getnameinfo()

Signed-off-by: Casey Bodley <cbodley@citi.umich.edu>
This commit is contained in:
Casey Bodley 2011-01-05 14:49:08 -05:00
parent 9c960aa409
commit 089a52906b

View file

@ -46,7 +46,7 @@ static int get_client_for_netaddr(
IN uint32_t wsize, IN uint32_t wsize,
IN uint32_t rsize, IN uint32_t rsize,
IN nfs41_rpc_clnt *rpc, IN nfs41_rpc_clnt *rpc,
OUT char **server_name, OUT OPTIONAL char *server_name,
OUT CLIENT **client_out) OUT CLIENT **client_out)
{ {
int status = ERROR_NETWORK_UNREACHABLE; int status = ERROR_NETWORK_UNREACHABLE;
@ -62,13 +62,10 @@ static int get_client_for_netaddr(
if (addr == NULL) if (addr == NULL)
goto out_free_conf; goto out_free_conf;
*server_name = calloc(NFS41_HOSTNAME_LEN, sizeof(char)); if (server_name) {
if (*server_name == NULL) getnameinfo(addr->buf, addr->len, server_name, NI_MAXHOST, NULL, 0, 0);
goto out_free_addr; dprintf(1, "servername is %s\n", server_name);
}
getnameinfo(addr->buf, addr->len, *server_name, NFS41_HOSTNAME_LEN, NULL, 0, 0);
dprintf(1, "servername is %s\n", *server_name);
dprintf(1, "callback function %p args %p\n", nfs41_handle_callback, rpc); dprintf(1, "callback function %p args %p\n", nfs41_handle_callback, rpc);
client = clnt_tli_create(RPC_ANYFD, nconf, addr, client = clnt_tli_create(RPC_ANYFD, nconf, addr,
NFS41_RPC_PROGRAM, NFS41_RPC_VERSION, wsize, rsize, NFS41_RPC_PROGRAM, NFS41_RPC_VERSION, wsize, rsize,
@ -77,8 +74,7 @@ static int get_client_for_netaddr(
*client_out = client; *client_out = client;
status = NO_ERROR; status = NO_ERROR;
goto out_free_addr; goto out_free_addr;
} else }
free(*server_name);
out_free_addr: out_free_addr:
freenetbuf(addr); freenetbuf(addr);
out_free_conf: out_free_conf:
@ -92,7 +88,7 @@ static int get_client_for_multi_addr(
IN uint32_t wsize, IN uint32_t wsize,
IN uint32_t rsize, IN uint32_t rsize,
IN nfs41_rpc_clnt *rpc, IN nfs41_rpc_clnt *rpc,
OUT char **server_name, OUT OPTIONAL char *server_name,
OUT CLIENT **client_out, OUT CLIENT **client_out,
OUT uint32_t *addr_index) OUT uint32_t *addr_index)
{ {
@ -125,8 +121,8 @@ int nfs41_rpc_clnt_create(
uint32_t addr_index; uint32_t addr_index;
int status; int status;
char machname[MAXHOSTNAMELEN + 1]; char machname[MAXHOSTNAMELEN + 1];
char server_name[NI_MAXHOST];
gid_t gids[1]; gid_t gids[1];
char *server_name = NULL;
rpc = calloc(1, sizeof(nfs41_rpc_clnt)); rpc = calloc(1, sizeof(nfs41_rpc_clnt));
if (rpc == NULL) { if (rpc == NULL) {
@ -141,7 +137,7 @@ int nfs41_rpc_clnt_create(
goto out_free_rpc_clnt; goto out_free_rpc_clnt;
} }
status = get_client_for_multi_addr(addrs, wsize, rsize, needcb?rpc:NULL, status = get_client_for_multi_addr(addrs, wsize, rsize, needcb?rpc:NULL,
&server_name, &client, &addr_index); server_name, &client, &addr_index);
if (status) { if (status) {
clnt_pcreateerror("connecting failed"); clnt_pcreateerror("connecting failed");
goto out_free_rpc_cond; goto out_free_rpc_cond;
@ -191,7 +187,6 @@ int nfs41_rpc_clnt_create(
dprintf(1, "nfs41_rpc_clnt_create: successfully created %s\n", dprintf(1, "nfs41_rpc_clnt_create: successfully created %s\n",
secflavorop2name(sec_flavor)); secflavorop2name(sec_flavor));
free(server_name);
rpc->rpc = client; rpc->rpc = client;
/* keep a copy of the address and buffer sizes for reconnect */ /* keep a copy of the address and buffer sizes for reconnect */
@ -210,7 +205,6 @@ out:
return status; return status;
out_err_client: out_err_client:
clnt_destroy(client); clnt_destroy(client);
free(server_name);
out_free_rpc_cond: out_free_rpc_cond:
CloseHandle(rpc->cond); CloseHandle(rpc->cond);
out_free_rpc_clnt: out_free_rpc_clnt:
@ -261,16 +255,14 @@ static int rpc_reconnect(
CLIENT *client = NULL; CLIENT *client = NULL;
uint32_t addr_index; uint32_t addr_index;
int status; int status;
char *server_name = NULL;
AcquireSRWLockExclusive(&rpc->lock); AcquireSRWLockExclusive(&rpc->lock);
status = get_client_for_multi_addr(&rpc->addrs, rpc->wsize, rpc->rsize, status = get_client_for_multi_addr(&rpc->addrs, rpc->wsize, rpc->rsize,
rpc, &server_name, &client, &addr_index); rpc, NULL, &client, &addr_index);
if (status) if (status)
goto out_unlock; goto out_unlock;
free(server_name);
client->cl_auth = rpc->rpc->cl_auth; client->cl_auth = rpc->rpc->cl_auth;
if (send_null(client) != RPC_SUCCESS) if (send_null(client) != RPC_SUCCESS)
goto out_err_client; goto out_err_client;