diff mbox

[01/17] libnsdb: Check "host" parameter

Message ID 20140102202703.2964.27008.stgit@seurat.1015granger.net
State Accepted
Headers show

Commit Message

Chuck Lever Jan. 2, 2014, 8:27 p.m. UTC
libnsdb is intended to provide a public API, and as such, it is
careful to check all incoming parameters.  For some reason, though,
it doesn't verify that host != NULL.  Add that check.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---
 src/libnsdb/administrator.c |   55 +++++++++++++++++++++++++++++++++++++++++++
 src/libnsdb/fileserver.c    |   35 +++++++++++++++++++++++++++
 2 files changed, 90 insertions(+)
diff mbox

Patch

diff --git a/src/libnsdb/administrator.c b/src/libnsdb/administrator.c
index 2e4aa0d..7fc5f71 100644
--- a/src/libnsdb/administrator.c
+++ b/src/libnsdb/administrator.c
@@ -276,6 +276,11 @@  FedFsStatus
 nsdb_create_fsn_s(nsdb_t host, const char *nce, const char *fsn_uuid,
 		const unsigned int ttl, unsigned int *ldap_err)
 {
+	if (host == NULL) {
+		xlog(L_ERROR, "%s: Invalid host parameter", __func__);
+		return FEDFS_ERR_INVAL;
+	}
+
 	if (host->fn_ldap == NULL) {
 		xlog(L_ERROR, "%s: NSDB not open", __func__);
 		return FEDFS_ERR_INVAL;
@@ -549,6 +554,11 @@  nsdb_delete_fsn_s(nsdb_t host, const char *nce, const char *fsn_uuid,
 	FedFsStatus retval;
 	char *dn;
 
+	if (host == NULL) {
+		xlog(L_ERROR, "%s: Invalid host parameter", __func__);
+		return FEDFS_ERR_INVAL;
+	}
+
 	if (host->fn_ldap == NULL) {
 		xlog(L_ERROR, "%s: NSDB not open", __func__);
 		return FEDFS_ERR_INVAL;
@@ -891,6 +901,11 @@  nsdb_create_fsls_s(nsdb_t host, const char *nce, struct fedfs_fsl *fsls,
 	struct fedfs_fsl *fsl, *progress;
 	FedFsStatus retval;
 
+	if (host == NULL) {
+		xlog(L_ERROR, "%s: Invalid host parameter", __func__);
+		return FEDFS_ERR_INVAL;
+	}
+
 	if (host->fn_ldap == NULL) {
 		xlog(D_GENERAL, "%s: NSDB not open", __func__);
 		return FEDFS_ERR_INVAL;
@@ -1072,6 +1087,11 @@  nsdb_delete_fsl_s(nsdb_t host, const char *nce, const char *fsl_uuid,
 	FedFsStatus retval;
 	char *dn;
 
+	if (host == NULL) {
+		xlog(L_ERROR, "%s: Invalid host parameter", __func__);
+		return FEDFS_ERR_INVAL;
+	}
+
 	if (host->fn_ldap == NULL) {
 		xlog(L_ERROR, "%s: NSDB not open", __func__);
 		return FEDFS_ERR_INVAL;
@@ -1198,6 +1218,11 @@  nsdb_update_fsl_s(nsdb_t host, const char *nce, const char *fsl_uuid,
 	FedFsStatus retval;
 	char *dn;
 
+	if (host == NULL) {
+		xlog(L_ERROR, "%s: Invalid host parameter", __func__);
+		return FEDFS_ERR_INVAL;
+	}
+
 	if (host->fn_ldap == NULL) {
 		xlog(L_ERROR, "%s: NSDB not open", __func__);
 		return FEDFS_ERR_INVAL;
@@ -1385,6 +1410,11 @@  nsdb_create_simple_nce_s(nsdb_t host, const char *parent,
 	FedFsStatus retval;
 	char *nce;
 
+	if (host == NULL) {
+		xlog(L_ERROR, "%s: Invalid host parameter", __func__);
+		return FEDFS_ERR_INVAL;
+	}
+
 	if (host->fn_ldap == NULL) {
 		xlog(L_ERROR, "%s: NSDB not open", __func__);
 		return FEDFS_ERR_INVAL;
@@ -1475,6 +1505,11 @@  nsdb_update_nci_s(nsdb_t host, const char *nce, unsigned int *ldap_err)
 	FedFsStatus retval;
 	char *context;
 
+	if (host == NULL) {
+		xlog(L_ERROR, "%s: Invalid host parameter", __func__);
+		return FEDFS_ERR_INVAL;
+	}
+
 	if (host->fn_ldap == NULL) {
 		xlog(L_ERROR, "%s: NSDB not open", __func__);
 		return FEDFS_ERR_INVAL;
@@ -1590,6 +1625,11 @@  nsdb_remove_nci_s(nsdb_t host, const char *nce, unsigned int *ldap_err)
 	FedFsStatus retval;
 	char *context;
 
+	if (host == NULL) {
+		xlog(L_ERROR, "%s: Invalid host parameter", __func__);
+		return FEDFS_ERR_INVAL;
+	}
+
 	if (host->fn_ldap == NULL) {
 		xlog(L_ERROR, "%s: NSDB not open", __func__);
 		return FEDFS_ERR_INVAL;
@@ -1737,6 +1777,11 @@  nsdb_delete_nsdb_s(nsdb_t host, const char *nce, unsigned int *ldap_err)
 {
 	FedFsStatus retval;
 
+	if (host == NULL) {
+		xlog(L_ERROR, "%s: Invalid host parameter", __func__);
+		return FEDFS_ERR_INVAL;
+	}
+
 	if (host->fn_ldap == NULL) {
 		xlog(L_ERROR, "%s: NSDB not open", __func__);
 		return FEDFS_ERR_INVAL;
@@ -1780,6 +1825,11 @@  nsdb_attr_add_s(nsdb_t host, const char *dn, const char *attr,
 {
 	struct berval bval;
 
+	if (host == NULL) {
+		xlog(L_ERROR, "%s: Invalid host parameter", __func__);
+		return FEDFS_ERR_INVAL;
+	}
+
 	if (host->fn_ldap == NULL) {
 		xlog(L_ERROR, "%s: NSDB not open", __func__);
 		return FEDFS_ERR_INVAL;
@@ -1828,6 +1878,11 @@  nsdb_attr_delete_s(nsdb_t host, const char *dn, const char *attr,
 {
 	struct berval bval;
 
+	if (host == NULL) {
+		xlog(L_ERROR, "%s: Invalid host parameter", __func__);
+		return FEDFS_ERR_INVAL;
+	}
+
 	if (host->fn_ldap == NULL) {
 		xlog(L_ERROR, "%s: NSDB not open", __func__);
 		return FEDFS_ERR_INVAL;
diff --git a/src/libnsdb/fileserver.c b/src/libnsdb/fileserver.c
index fdd0878..9484591 100644
--- a/src/libnsdb/fileserver.c
+++ b/src/libnsdb/fileserver.c
@@ -606,6 +606,11 @@  nsdb_get_ncedn_s(nsdb_t host, const char *naming_context, char **dn,
 {
 	FedFsStatus retval;
 
+	if (host == NULL) {
+		xlog(L_ERROR, "%s: Invalid host parameter", __func__);
+		return FEDFS_ERR_INVAL;
+	}
+
 	if (host->fn_ldap == NULL) {
 		xlog(L_ERROR, "%s: NSDB not open", __func__);
 		return FEDFS_ERR_INVAL;
@@ -726,6 +731,11 @@  nsdb_get_naming_contexts_s(nsdb_t host, char ***contexts,
 	char **tmp;
 	int rc;
 
+	if (host == NULL) {
+		xlog(L_ERROR, "%s: Invalid host parameter", __func__);
+		return FEDFS_ERR_INVAL;
+	}
+
 	if (host->fn_ldap == NULL) {
 		xlog(L_ERROR, "%s: NSDB not open", __func__);
 		return FEDFS_ERR_INVAL;
@@ -1285,6 +1295,11 @@  nsdb_resolve_fsn_s(nsdb_t host, const char *nce, const char *fsn_uuid,
 	FedFsStatus retval;
 	int i, j;
 
+	if (host == NULL) {
+		xlog(L_ERROR, "%s: Invalid host parameter", __func__);
+		return FEDFS_ERR_INVAL;
+	}
+
 	if (host->fn_ldap == NULL) {
 		xlog(L_ERROR, "%s: NSDB not open", __func__);
 		return FEDFS_ERR_INVAL;
@@ -1596,6 +1611,11 @@  nsdb_get_fsn_s(nsdb_t host, const char *nce, const char *fsn_uuid,
 	FedFsStatus retval;
 	int i, j;
 
+	if (host == NULL) {
+		xlog(L_ERROR, "%s: Invalid host parameter", __func__);
+		return FEDFS_ERR_INVAL;
+	}
+
 	if (host->fn_ldap == NULL) {
 		xlog(L_ERROR, "%s: NSDB not open", __func__);
 		return FEDFS_ERR_INVAL;
@@ -1850,6 +1870,11 @@  nsdb_list_s(nsdb_t host, const char *nce, char ***fsns, unsigned int *ldap_err)
 	FedFsStatus retval;
 	int i, j;
 
+	if (host == NULL) {
+		xlog(L_ERROR, "%s: Invalid host parameter", __func__);
+		return FEDFS_ERR_INVAL;
+	}
+
 	if (host->fn_ldap == NULL) {
 		xlog(L_ERROR, "%s: NSDB not open", __func__);
 		return FEDFS_ERR_INVAL;
@@ -1960,6 +1985,11 @@  nsdb_ping_nsdb_s(nsdb_t host, unsigned int *ldap_err)
 	FedFsStatus retval;
 	char **contexts = NULL;
 
+	if (host == NULL) {
+		xlog(L_ERROR, "%s: Invalid host parameter", __func__);
+		return FEDFS_ERR_INVAL;
+	}
+
 	if (host->fn_ldap == NULL) {
 		xlog(L_ERROR, "%s: NSDB not open", __func__);
 		return FEDFS_ERR_INVAL;
@@ -2082,6 +2112,11 @@  nsdb_find_naming_context_s(nsdb_t host, const char *entry, char **context,
 	char **contexts = NULL;
 	FedFsStatus retval;
 
+	if (host == NULL) {
+		xlog(L_ERROR, "%s: Invalid host parameter", __func__);
+		return FEDFS_ERR_INVAL;
+	}
+
 	if (host->fn_ldap == NULL) {
 		xlog(L_ERROR, "%s: NSDB not open", __func__);
 		return FEDFS_ERR_INVAL;