PERFORCE change 32011 for review
Robert Watson
rwatson at FreeBSD.org
Thu May 29 16:29:51 GMT 2003
http://perforce.freebsd.org/chv.cgi?CH=32011
Change 32011 by rwatson at rwatson_tislabs on 2003/05/29 09:29:44
Use strsep() to pass Biba and MLS labels into their elements
rather than hand-parsing.
Affected files ...
.. //depot/projects/trustedbsd/mac/sys/security/mac_biba/mac_biba.c#206 edit
.. //depot/projects/trustedbsd/mac/sys/security/mac_mls/mac_mls.c#165 edit
Differences ...
==== //depot/projects/trustedbsd/mac/sys/security/mac_biba/mac_biba.c#206 (text+ko) ====
@@ -765,38 +765,30 @@
static int
mac_biba_parse(struct mac_biba *mac_biba, char *string)
{
- char *range, *rangeend, *rangehigh, *rangelow, *single;
+ char *rangehigh, *rangelow, *single;
int error;
- /* Do we have a range? */
- single = string;
- range = index(string, '(');
- if (range == single)
+ single = strsep(&string, "(");
+ if (*single == '\0')
single = NULL;
- rangelow = rangehigh = NULL;
- if (range != NULL) {
- /* Nul terminate the end of the single string. */
- *range = '\0';
- range++;
- rangelow = range;
- rangehigh = index(rangelow, '-');
- if (rangehigh == NULL)
+
+ if (string != NULL) {
+ rangelow = strsep(&string, "-");
+ if (string == NULL)
return (EINVAL);
- rangehigh++;
- if (*rangelow == '\0' || *rangehigh == '\0')
+ rangehigh = strsep(&string, ")");
+ if (string == NULL)
return (EINVAL);
- rangeend = index(rangehigh, ')');
- if (rangeend == NULL)
+ if (*string != '\0')
return (EINVAL);
- if (*(rangeend + 1) != '\0')
- return (EINVAL);
- /* Nul terminate the ends of the ranges. */
- *(rangehigh - 1) = '\0';
- *rangeend = '\0';
+ } else {
+ rangelow = NULL;
+ rangehigh = NULL;
}
+
KASSERT((rangelow != NULL && rangehigh != NULL) ||
(rangelow == NULL && rangehigh == NULL),
- ("mac_biba_internalize_label: range mismatch"));
+ ("mac_biba_parse: range mismatch"));
bzero(mac_biba, sizeof(*mac_biba));
if (single != NULL) {
==== //depot/projects/trustedbsd/mac/sys/security/mac_mls/mac_mls.c#165 (text+ko) ====
@@ -730,38 +730,30 @@
static int
mac_mls_parse(struct mac_mls *mac_mls, char *string)
{
- char *range, *rangeend, *rangehigh, *rangelow, *single;
+ char *rangehigh, *rangelow, *single;
int error;
- /* Do we have a range? */
- single = string;
- range = index(string, '(');
- if (range == single)
+ single = strsep(&string, "(");
+ if (*single == '\0')
single = NULL;
- rangelow = rangehigh = NULL;
- if (range != NULL) {
- /* Nul terminate the end of the single string. */
- *range = '\0';
- range++;
- rangelow = range;
- rangehigh = index(rangelow, '-');
- if (rangehigh == NULL)
+
+ if (string != NULL) {
+ rangelow = strsep(&string, "-");
+ if (string == NULL)
return (EINVAL);
- rangehigh++;
- if (*rangelow == '\0' || *rangehigh == '\0')
+ rangehigh = strsep(&string, ")");
+ if (string == NULL)
return (EINVAL);
- rangeend = index(rangehigh, ')');
- if (rangeend == NULL)
+ if (*string != '\0')
return (EINVAL);
- if (*(rangeend + 1) != '\0')
- return (EINVAL);
- /* Nul terminate the ends of the ranges. */
- *(rangehigh - 1) = '\0';
- *rangeend = '\0';
+ } else {
+ rangelow = NULL;
+ rangehigh = NULL;
}
+
KASSERT((rangelow != NULL && rangehigh != NULL) ||
(rangelow == NULL && rangehigh == NULL),
- ("mac_mls_internalize_label: range mismatch"));
+ ("mac_mls_parse: range mismatch"));
bzero(mac_mls, sizeof(*mac_mls));
if (single != NULL) {
To Unsubscribe: send mail to majordomo at trustedbsd.org
with "unsubscribe trustedbsd-cvs" in the body of the message
More information about the trustedbsd-cvs
mailing list