From: J. Bruce Fields Date: Sat, 9 Jan 2010 17:44:57 +0000 (-0700) Subject: mountd: minor v4root_set cleanup, check strdup return X-Git-Tag: nfs-utils-1-2-2-rc6~2 X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=e0819debc9d1d322e06ca4047a125a4fd8176d13;p=nfs-utils.git mountd: minor v4root_set cleanup, check strdup return Move more of v4root_set into a helper function. Also, check the return value from strdup. (We don't really handle the error well yet--we'll end up giving negative replies to export upcalls when we should be giving the kernel exports, resulting in spurious -ENOENTs or -ESTALE's--but that's better than crashing with a NULL dereference.) Signed-off-by: J. Bruce Fields --- diff --git a/utils/mountd/v4root.c b/utils/mountd/v4root.c index ac800b3..7fd6af3 100644 --- a/utils/mountd/v4root.c +++ b/utils/mountd/v4root.c @@ -137,6 +137,31 @@ int pseudofs_update(char *hostname, char *path, nfs_export *source) return 0; } +static int v4root_add_parents(nfs_export *exp) +{ + char *hostname = exp->m_export.e_hostname; + char *path; + char *ptr; + + path = strdup(exp->m_export.e_path); + if (!path) + return -ENOMEM; + for (ptr = path + 1; ptr; ptr = strchr(ptr, '/')) { + int ret; + char saved; + + saved = *ptr; + *ptr = '\0'; + ret = pseudofs_update(hostname, path, exp); + if (ret) + return ret; + *ptr = saved; + ptr++; + } + free(path); + return 0; +} + /* * Create pseudo exports by running through the real export * looking at the components of the path that make up the export. @@ -148,9 +173,7 @@ void v4root_set() { nfs_export *exp; - int i; - char *path, *ptr; - char *hostname; + int i, ret; if (!v4root_needed) return; @@ -159,8 +182,6 @@ v4root_set() for (i = 0; i < MCL_MAXTYPES; i++) { for (exp = exportlist[i].p_head; exp; exp = exp->m_next) { - hostname = exp->m_export.e_hostname; - if (exp->m_export.e_flags & NFSEXP_V4ROOT) /* * We just added this one, so its @@ -168,19 +189,8 @@ v4root_set() */ continue; - path = strdup(exp->m_export.e_path); - for (ptr = path + 1; ptr; ptr = strchr(ptr, '/')) { - int ret; - char saved; - - saved = *ptr; - *ptr = '\0'; - ret = pseudofs_update(hostname, path, exp); - /* XXX: error handling */ - *ptr = saved; - ptr++; - } - free(path); + ret = v4root_add_parents(exp); + /* XXX: error handling! */ } } }