diff mbox

[08/15] libnsdb: nsdb_list_s() returns FEDFS_OK without updating "fsns"

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

Commit Message

Chuck Lever Oct. 25, 2011, 4:49 p.m. UTC
Trying the nsdb-list command against an empty NSDB causes a
segmentation fault.  This is because nsdb_list_s() found no FSN
records.  It did not alter the "fsns" output argument, but returned
FEDFS_OK anyway.

nsdb_list_s() needs to return an appropriate error code if it does not
plant anything in the "fsns" output argument.  To address this, copy
the logic from the tail of nsdb_resolve_fsn_s().

And, fix the nsdb-list command to recognize FEDFS_ERR_NSDB_NOFSN and
report an appropriate error message.

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
---

 src/libnsdb/fileserver.c |    9 ++++++---
 src/nsdbc/nsdb-list.c    |    4 ++++
 2 files changed, 10 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/src/libnsdb/fileserver.c b/src/libnsdb/fileserver.c
index 22d192e..a7631e8 100644
--- a/src/libnsdb/fileserver.c
+++ b/src/libnsdb/fileserver.c
@@ -1217,10 +1217,13 @@  nsdb_list_s(nsdb_t host, const char *nce, char ***fsns, unsigned int *ldap_err)
 	if (j == 0)
 		goto out;
 
-	for (j = 0; nce_list[j] != NULL; j++)
-		nsdb_list_find_entries_s(host->fn_ldap, nce_list[j],
+	for (j = 0; nce_list[j] != NULL; j++) {
+		retval = nsdb_list_find_entries_s(host->fn_ldap,
+						nce_list[j],
 						fsns, ldap_err);
-	retval = FEDFS_OK;
+		if (retval == FEDFS_OK)
+			break;
+	}
 
 out:
 	nsdb_free_string_array(nce_list);
diff --git a/src/nsdbc/nsdb-list.c b/src/nsdbc/nsdb-list.c
index 6787076..1ac04b0 100644
--- a/src/nsdbc/nsdb-list.c
+++ b/src/nsdbc/nsdb-list.c
@@ -256,6 +256,10 @@  main(int argc, char **argv)
 			nsdb_list_resolve_and_display_fsn(host, nce, fsns[i]);
 		nsdb_free_string_array(fsns);
 		break;
+	case FEDFS_ERR_NSDB_NOFSN:
+		fprintf(stderr, "NSDB %s:%u has no FSN records\n",
+			nsdbname, nsdbport);
+		break;
 	case FEDFS_ERR_NSDB_NONCE:
 		if (nce == NULL)
 			fprintf(stderr, "NSDB %s:%u has no NCE\n",