Skip to contentSkip to conversation

libselinux: set errno in string functions

PATCH In review Eamon Walsh 2 participants 2 messages Jun 1, 2007 – Jun 5, 2007 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libselinux: set errno in string functions

Set errno to EINVAL in string functions on bad input.

---

stringrep.c | 10 ++++++++--

1 file changed, 8 insertions(+), 2 deletions(-)
src/stringrep.c +0 -0
@@ -160,6 +160,7 @@
		}
	}
+	errno = EINVAL;
	return 0;
}

@@ -197,13 +198,17 @@

			return av_perm_to_string[i].value;
	}
+	errno = EINVAL;
	return 0;
}

const char *security_class_to_string(security_class_t tclass) {
- tclass = (tclass > 0 && tclass < NCLASSES) ? tclass : 0;
- return class_to_string_data.str + class_to_string[tclass];
+ if (tclass > 0 && tclass < NCLASSES)
+ return class_to_string_data.str + class_to_string[tclass];
+
+ errno = EINVAL;
+ return NULL;
}

const char *security_av_perm_to_string(security_class_t tclass, @@ -242,6 +247,7 @@

				+ av_perm_to_string[i].nameidx;
	}
+	errno = EINVAL;
	return NULL;
}
Signature · 8 lines
Eamon Walsh <[email protected]>
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.
Acked-by on v1 1/1
#1 lore raw
Quoted 3 lines · Eamon Walsh

Set errno to EINVAL in string functions on bad input.

Merge at will.

Quoted 47 lines

---

 stringrep.c |   10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
src/stringrep.c +8 -2
@@ -160,6 +160,7 @@
 		}
 	}
 
+	errno = EINVAL;
 	return 0;
 }
 
@@ -197,13 +198,17 @@
 			return av_perm_to_string[i].value;
 	}
 
+	errno = EINVAL;
 	return 0;
 }
 
 const char *security_class_to_string(security_class_t tclass)
 {
-	tclass = (tclass > 0 && tclass < NCLASSES) ? tclass : 0;
-	return class_to_string_data.str + class_to_string[tclass];
+	if (tclass > 0 && tclass < NCLASSES)
+		return class_to_string_data.str + class_to_string[tclass];
+
+	errno = EINVAL;
+	return NULL;
 }
 
 const char *security_av_perm_to_string(security_class_t tclass,
@@ -242,6 +247,7 @@
 				+ av_perm_to_string[i].nameidx;
 	}
 
+	errno = EINVAL;
 	return NULL;
 }
 
Signature · 8 lines
Stephen Smalley
National Security Agency


--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to [email protected] with
the words "unsubscribe selinux" without quotes as the message.