From 739df145d600a7beb21050a5cb95b6b7ae184934 Mon Sep 17 00:00:00 2001 From: Ronnie Sahlberg Date: Sat, 25 Jun 2011 11:06:53 +1000 Subject: [PATCH] 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. --- examples/nfsclient-sync.c | 20 ++++++++++++-------- lib/libnfs-sync.c | 7 ++++++- 2 files changed, 18 insertions(+), 9 deletions(-) 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; -- 2.34.1