Skip to contentSkip to conversation

Handle address parsing errors in export_find()

PATCH In review Chuck Lever 2 participants 4 messages Apr 15, 2010 – Apr 16, 2010 1 message not in the archive

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover Handle address parsing errors in export_find()

Steve-

Two more short subjects in the mountd IPv6 series.

---

Chuck Lever (2):
libexport.a: export_find() should handle address parsing errors libexport.a: Add export_free()

 support/export/export.c |   31 +++++++++++++++++++++----------
 1 files changed, 21 insertions(+), 10 deletions(-)
Signature · 1 line
Chuck Lever

A message that is not in the archive (sent off-list or not yet received): 20100415152401.4716.83632.stgit-bi+AKbBUZKY6gyzm1THtWbp2dZbC/[email protected]

#2 lore raw

PATCH 1/2 libexport.a: Add export_free()

Clean up: Introduce a helper to free an nfs_export record.

---

 support/export/export.c |   27 +++++++++++++++++----------
 1 files changed, 17 insertions(+), 10 deletions(-)
support/export/export.c +17 -10
index 42e78f6..ddc8a84 100644
@@ -28,6 +28,18 @@ static int	export_check(nfs_export *, struct hostent *, char *);
 static nfs_export *
 		export_allowed_internal(struct hostent *hp, char *path);
 
+static void
+export_free(nfs_export *exp)
+{
+	xfree(exp->m_export.e_squids);
+	xfree(exp->m_export.e_sqgids);
+	free(exp->m_export.e_mountpoint);
+	free(exp->m_export.e_fslocdata);
+
+	xfree(exp->m_export.e_hostname);
+	xfree(exp);
+}
+
 static void warn_duplicated_exports(nfs_export *exp, struct exportent *eep)
 {
 	if (exp->m_export.e_flags != eep->e_flags) {
@@ -260,6 +272,10 @@ export_check(nfs_export *exp, struct hostent *hp, char *path)
 	return client_check(exp->m_client, hp);
 }
 
+/**
+ * export_freeall - deallocate all nfs_export records
+ *
+ */
 void
 export_freeall(void)
 {
@@ -270,16 +286,7 @@ export_freeall(void)
 		for (exp = exportlist[i].p_head; exp; exp = nxt) {
 			nxt = exp->m_next;
 			client_release(exp->m_client);
-			if (exp->m_export.e_squids)
-				xfree(exp->m_export.e_squids);
-			if (exp->m_export.e_sqgids)
-				xfree(exp->m_export.e_sqgids);
-			if (exp->m_export.e_mountpoint)
-				free(exp->m_export.e_mountpoint);
-			if (exp->m_export.e_fslocdata)
-				free(exp->m_export.e_fslocdata);
-			xfree(exp->m_export.e_hostname);
-			xfree(exp);
+			export_free(exp);
 		}
 		for (j = 0; j < HASH_TABLE_SIZE; j++) {
 			exportlist[i].entries[j].p_first = NULL;
#3 lore raw

PATCH 2/2 libexport.a: export_find() should handle address parsing errors

In reply to a message not in the archive

An address mask parsing error can cause client_init(), and therefore client_dup(), to make our process exit suddenly. Soon we want to add more complex address parsing in client_init(), so we need this interface to be a little more robust.

Since export_find() can return NULL in some cases, it can handle NULL returns from its subroutines if an address parsing error occurs, or if memory is exhausted. Allow for client_dup() to return NULL instead of exiting sideways.

---

 support/export/export.c |    4 ++++
 1 files changed, 4 insertions(+), 0 deletions(-)
support/export/export.c +4 -0
index ddc8a84..3e4da69 100644
@@ -129,6 +129,10 @@ export_dup(nfs_export *exp, struct hostent *hp)
 	if (exp->m_export.e_hostname)
 		new->m_export.e_hostname = xstrdup(exp->m_export.e_hostname);
 	clp = client_dup(exp->m_client, hp);
+	if (clp == NULL) {
+		export_free(new);
+		return NULL;
+	}
 	clp->m_count++;
 	new->m_client = clp;
 	new->m_mayexport = exp->m_mayexport;
#4 lore raw
In reply to a message not in the archive
Quoted 9 lines · Chuck Lever

Steve-

Two more short subjects in the mountd IPv6 series.

---

Chuck Lever (2):
libexport.a: export_find() should handle address parsing errors libexport.a: Add export_free()

Committed and pushed!

steved.