1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-10-19 02:29:40 +00:00

linux/libshare: nfs: don't needlessly strdup() hostspec

Reviewed-by: Don Brady <don.brady@delphix.com>
Reviewed-by: Brian Behlendorf <behlendorf1@llnl.gov>
Reviewed-by: John Kennedy <john.kennedy@delphix.com>
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Closes #12067
This commit is contained in:
наб 2021-05-17 20:34:04 +02:00 committed by Brian Behlendorf
parent 605e03e51a
commit 9d4a44f0b8

View File

@ -247,8 +247,8 @@ foreach_nfs_host(sa_share_impl_t impl_share, FILE *tmpfile,
/*
* Converts a Solaris NFS host specification to its Linux equivalent.
*/
static int
get_linux_hostspec(const char *solaris_hostspec, char **plinux_hostspec)
static const char *
get_linux_hostspec(const char *solaris_hostspec)
{
/*
* For now we just support CIDR masks (e.g. @192.168.0.0/16) and host
@ -259,16 +259,10 @@ get_linux_hostspec(const char *solaris_hostspec, char **plinux_hostspec)
* Solaris host specifier, e.g. @192.168.0.0/16; we just need
* to skip the @ in this case
*/
*plinux_hostspec = strdup(solaris_hostspec + 1);
return (solaris_hostspec + 1);
} else {
*plinux_hostspec = strdup(solaris_hostspec);
return (solaris_hostspec);
}
if (*plinux_hostspec == NULL) {
return (SA_NO_MEMORY);
}
return (SA_OK);
}
/*
@ -397,25 +391,18 @@ nfs_add_entry(FILE *tmpfile, const char *sharepath,
const char *host, const char *security, const char *access_opts,
void *pcookie)
{
int error;
char *linuxhost;
const char *linux_opts = (const char *)pcookie;
error = get_linux_hostspec(host, &linuxhost);
if (error != SA_OK)
return (error);
if (linux_opts == NULL)
linux_opts = "";
if (fprintf(tmpfile, "%s %s(sec=%s,%s,%s)\n", sharepath, linuxhost,
security, access_opts, linux_opts) < 0) {
if (fprintf(tmpfile, "%s %s(sec=%s,%s,%s)\n", sharepath,
get_linux_hostspec(host), security, access_opts,
linux_opts) < 0) {
fprintf(stderr, "failed to write to temporary file\n");
free(linuxhost);
return (SA_SYSTEM_ERR);
}
free(linuxhost);
return (SA_OK);
}