From: Ronnie Sahlberg Date: Sat, 25 Jun 2011 01:06:53 +0000 (+1000) Subject: fix crash in mount/export X-Git-Tag: upstream/1.9.6^2~389 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=739df145d600a7beb21050a5cb95b6b7ae184934;p=deb_libnfs.git fix crash in mount/export need to check that status is OK before we start dereferencing the 'export' pointers or else we will segv. this could happen if trying to pull the list of exports from a host that does not have mountd running, or if we can not connect at all to the host. --- diff --git a/examples/nfsclient-sync.c b/examples/nfsclient-sync.c index 521bf4e..a5af3ce 100644 --- a/examples/nfsclient-sync.c +++ b/examples/nfsclient-sync.c @@ -64,15 +64,19 @@ int main(int argc _U_, char *argv[] _U_) struct statvfs svfs; exports export, tmp; - printf("exports on server %s\n", SERVER); export = mount_getexports(SERVER); - tmp = export; - while (tmp != NULL) { - printf("Export: %s\n", tmp->ex_dir); - tmp = tmp->ex_next; - } - mount_free_export_list(export); - + if (export != NULL) { + printf("exports on server %s\n", SERVER); + tmp = export; + while (tmp != NULL) { + printf("Export: %s\n", tmp->ex_dir); + tmp = tmp->ex_next; + } + + mount_free_export_list(export); + } else { + printf("no exports on server %s\n", SERVER); + } nfs = nfs_init_context(); if (nfs == NULL) { diff --git a/lib/libnfs-sync.c b/lib/libnfs-sync.c index 29c805c..4c8ba76 100644 --- a/lib/libnfs-sync.c +++ b/lib/libnfs-sync.c @@ -1069,7 +1069,7 @@ int nfs_link(struct nfs_context *nfs, const char *oldpath, const char *newpath) return cb_data.status; } -void mount_getexports_cb(struct rpc_context *mount_context _U_, int status, void *data, void *private_data) +void mount_getexports_cb(struct rpc_context *mount_context, int status, void *data, void *private_data) { struct sync_cb_data *cb_data = private_data; exports export = *(exports *)data; @@ -1078,6 +1078,11 @@ void mount_getexports_cb(struct rpc_context *mount_context _U_, int status, void cb_data->status = status; cb_data->return_data = NULL; + if (status != 0) { + rpc_set_error(mount_context, "mount/export call failed with \"%s\"", (char *)data); + return; + } + while (export != NULL) { exports new_export;