Skip to contentSkip to conversation

Handle NULL names better

PATCH In review Steve Dickson 1 participant 4 messages Apr 30, 2015 – May 4, 2015

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

PATCH 1/1 Handle NULL names better

Detect when an application passes in NULL names
and fail gracefully instead of crashing hard.

---
 libnfsidmap.c | 5 ++++-
 nss.c         | 3 +++
 2 files changed, 7 insertions(+), 1 deletion(-)
libnfsidmap.c +4 -1
index 833f94c..a8a9229 100644
@@ -100,8 +100,11 @@ static char * toupper_str(char *s)
 
 static int id_as_chars(char *name, uid_t *id)
 {
-	long int value = strtol(name, NULL, 10);
+	long int value;
 
+	if (name == NULL)
+		return 0;
+	value = strtol(name, NULL, 10);
 	if (value == 0) {
 		/* zero value ids are valid */
 		if (strcmp(name, "0") != 0)
nss.c +3 -0
index f8129fe..b3fef5a 100644
@@ -135,6 +135,9 @@ static char *strip_domain(const char *name, const char *domain)
 	char *l = NULL;
 	int len;
 
+	if (name == NULL)
+		goto out;
+
 	c = strrchr(name, '@');
 	if (c == NULL && domain != NULL)
 		goto out;
Signature · 1 line
2.1.0
#1 lore raw

PATCH 1/1 nfsidmap: make sure given arguments are valid

Detect when a given argument is invalid. Log
the error and exit gracefully

---
 utils/nfsidmap/nfsidmap.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
utils/nfsidmap/nfsidmap.c +4 -1
index 5d62078..1f5ba67 100644
@@ -323,7 +323,10 @@ int main(int argc, char **argv)
 	}
 	type = strtok(arg, ":");
 	value = strtok(NULL, ":");
-
+    if (value == NULL) {
+		xlog_err("Error: Null uid/gid value.");
+		return 1;
+	}
 	if (verbose) {
 		xlog_warn("key: 0x%lx type: %s value: %s timeout %ld",
 			key, type, value, timeout);
Signature · 1 line
2.1.0
#2 lore raw

Re: [PATCH] nfsidmap: make sure given arguments are valid

Quoted 4 lines · Steve Dickson

Detect when a given argument is invalid. Log
the error and exit gracefully

Committed...

steved.

Quoted 21 lines
---
 utils/nfsidmap/nfsidmap.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
utils/nfsidmap/nfsidmap.c +4 -1
index 5d62078..1f5ba67 100644
@@ -323,7 +323,10 @@ int main(int argc, char **argv)
 	}
 	type = strtok(arg, ":");
 	value = strtok(NULL, ":");
-
+    if (value == NULL) {
+		xlog_err("Error: Null uid/gid value.");
+		return 1;
+	}
 	if (verbose) {
 		xlog_warn("key: 0x%lx type: %s value: %s timeout %ld",
 			key, type, value, timeout);
#3 lore raw
In reply to Steve Dickson
Quoted 4 lines · Steve Dickson

Detect when an application passes in NULL names
and fail gracefully instead of crashing hard.

Committed...

steved.

Quoted 37 lines
---
 libnfsidmap.c | 5 ++++-
 nss.c         | 3 +++
 2 files changed, 7 insertions(+), 1 deletion(-)
libnfsidmap.c +4 -1
index 833f94c..a8a9229 100644
@@ -100,8 +100,11 @@ static char * toupper_str(char *s)
 
 static int id_as_chars(char *name, uid_t *id)
 {
-	long int value = strtol(name, NULL, 10);
+	long int value;
 
+	if (name == NULL)
+		return 0;
+	value = strtol(name, NULL, 10);
 	if (value == 0) {
 		/* zero value ids are valid */
 		if (strcmp(name, "0") != 0)
nss.c +3 -0
index f8129fe..b3fef5a 100644
@@ -135,6 +135,9 @@ static char *strip_domain(const char *name, const char *domain)
 	char *l = NULL;
 	int len;
 
+	if (name == NULL)
+		goto out;
+
 	c = strrchr(name, '@');
 	if (c == NULL && domain != NULL)
 		goto out;