Patchwork [2/7] libnsdb: nsdb_list_s() returns FEDFS_OK without updating "fsns"

login
register
mail settings
Submitter Chuck Lever
Date Nov. 3, 2011, 3:28 p.m.
Message ID <20111103152823.2445.46038.stgit@degas.1015granger.net>
Download mbox | patch
Permalink /patch/123456/
State Accepted
Headers show

Comments

Chuck Lever - Nov. 3, 2011, 3:28 p.m.
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(-)

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",