Skip to content

Commit

Permalink
linux/libshare: nfs: don't needlessly strdup() hostspec
Browse files Browse the repository at this point in the history
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 openzfs#12067
  • Loading branch information
nabijaczleweli authored and nicman23 committed Aug 22, 2022
1 parent 0e74301 commit d738d8d
Showing 1 changed file with 7 additions and 20 deletions.
27 changes: 7 additions & 20 deletions lib/libshare/os/linux/nfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
}

/*
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit d738d8d

Please sign in to comment.