diff options
author | Kyle Evans <kevans@FreeBSD.org> | 2020-04-15 18:39:12 +0000 |
---|---|---|
committer | Kyle Evans <kevans@FreeBSD.org> | 2020-04-15 18:39:12 +0000 |
commit | 3fb92d4cb104eb6903a1a808e892ba46c1834e31 (patch) | |
tree | dcaf22a8d806dab98f95d108ca1d7d11236e66d7 /sys/kern/kern_uuid.c | |
parent | bfe26b9707b642458ff8a8bb4c8d8ad71450f13c (diff) |
validate_uuid: absorb the rest of parse_uuid with a flags arg
This makes the naming annoyance (validate_uuid vs. parse_uuid) less of an
issue and centralizes all of the functionality into the new KPI while still
making the extra validation optional. The end-result is all the same as far
as hostuuid validation-only goes.
Notes
Notes:
svn path=/head/; revision=359980
Diffstat (limited to 'sys/kern/kern_uuid.c')
-rw-r--r-- | sys/kern/kern_uuid.c | 39 |
1 files changed, 19 insertions, 20 deletions
diff --git a/sys/kern/kern_uuid.c b/sys/kern/kern_uuid.c index 984a2b8cd6ac..4dbadc732de9 100644 --- a/sys/kern/kern_uuid.c +++ b/sys/kern/kern_uuid.c @@ -382,13 +382,21 @@ be_uuid_dec(void const *buf, struct uuid *uuid) } int -validate_uuid(const char *str, size_t size, struct uuid *uuid) +validate_uuid(const char *str, size_t size, struct uuid *uuid, int flags) { u_int c[11]; int n; - if (size == 0 || *str == '\0') + if (size == 0 || *str == '\0') { + /* An empty string may represent a nil UUID. */ + if ((flags & VUUIDF_EMPTYOK) != 0) { + if (uuid != NULL) + bzero(uuid, sizeof(*uuid)); + return (0); + } + return (EINVAL); + } /* The UUID string representation has a fixed length. */ if (size != 36) @@ -421,30 +429,21 @@ validate_uuid(const char *str, size_t size, struct uuid *uuid) uuid->node[n] = c[n + 5]; } - return (0); + if ((flags & VUUIDF_CHECKSEMANTICS) == 0) + return (0); + + return (((c[3] & 0x80) != 0x00 && /* variant 0? */ + (c[3] & 0xc0) != 0x80 && /* variant 1? */ + (c[3] & 0xe0) != 0xc0) ? EINVAL : 0); /* variant 2? */ } +#define VUUIDF_PARSEFLAGS (VUUIDF_EMPTYOK | VUUIDF_CHECKSEMANTICS) + int parse_uuid(const char *str, struct uuid *uuid) { - unsigned int clock_seq; - int ret; - - /* An empty string represents a nil UUID. */ - if (*str == '\0') { - bzero(uuid, sizeof(*uuid)); - return (0); - } - - ret = validate_uuid(str, strlen(str), uuid); - if (ret != 0) - return (ret); - /* Check semantics... */ - clock_seq = uuid->clock_seq_hi_and_reserved; - return (((clock_seq & 0x80) != 0x00 && /* variant 0? */ - (clock_seq & 0xc0) != 0x80 && /* variant 1? */ - (clock_seq & 0xe0) != 0xc0) ? EINVAL : 0); /* variant 2? */ + return (validate_uuid(str, strlen(str), uuid, VUUIDF_PARSEFLAGS)); } int |