Patchwork [10/11] libnsdb: Avoid passing NULL to strdup(3)

login
register
mail settings
Submitter Chuck Lever
Date Jan. 24, 2013, 6:36 p.m.
Message ID <20130124183603.13601.30397.stgit@seurat.1015granger.net>
Download mbox | patch
Permalink /patch/215473/
State Accepted
Headers show

Comments

Chuck Lever - Jan. 24, 2013, 6:36 p.m.
strdup(3) segfaults if it is passed NULL.

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

 src/libnsdb/nsdb.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)

Patch

diff --git a/src/libnsdb/nsdb.c b/src/libnsdb/nsdb.c
index 3bfb50e..e6c13c4 100644
--- a/src/libnsdb/nsdb.c
+++ b/src/libnsdb/nsdb.c
@@ -528,10 +528,12 @@  nsdb_new_nsdb(const char *hostname, const unsigned long port, nsdb_t *host)
 	char *hostname_tmp;
 	unsigned short port_tmp;
 
-	if (!nsdb_is_hostname_utf8(hostname))
-		return FEDFS_ERR_BADCHAR;
+	if (hostname == NULL || host == NULL)
+		return FEDFS_ERR_INVAL;
 	if (port > UINT16_MAX)
 		return FEDFS_ERR_INVAL;
+	if (!nsdb_is_hostname_utf8(hostname))
+		return FEDFS_ERR_BADCHAR;
 
 	port_tmp = LDAP_PORT;
 	if (port != 0)