|author||Kyle Evans <kevans@FreeBSD.org>||2020-04-15 03:59:26 +0000|
|committer||Kyle Evans <kevans@FreeBSD.org>||2020-04-15 03:59:26 +0000|
kern uuid: break format validation out into a separate KPI
This new KPI, validate_uuid, strictly validates the formatting of the input UUID and, optionally, populates a given struct uuid. As noted in the header, the key differences are that the new KPI won't recognize an empty string as a nil UUID and it won't do any kind of semantic validation on it. Also key is that populating a struct uuid is optional, so the caller doesn't necessarily need to allocate a bogus one on the stack just to validate the string. This KPI has specifically been broken out in support of D24288, which will preload /etc/hostid in loader so that early boot hostuuid users (e.g. anything that calls ether_gen_addr) can have a valid hostuuid to work with once it's been stashed in /etc/hostid.
Notes: svn path=/head/; revision=359953
Diffstat (limited to 'sys/sys')
1 files changed, 15 insertions, 0 deletions
diff --git a/sys/sys/uuid.h b/sys/sys/uuid.h
index e60af2180f14..9f0ea3d70fd4 100644
@@ -66,6 +66,21 @@ int uuid_ether_del(const uint8_t *);
int snprintf_uuid(char *, size_t, struct uuid *);
int printf_uuid(struct uuid *);
int sbuf_printf_uuid(struct sbuf *, struct uuid *);
+ * There are a few key differences between validate_uuid and parse_uuid:
+ * - The struct uuid * parameter to validate_uuid is optional, so the caller
+ * can simply validate UUID format without doing anything with the result.
+ * - validate_uuid will not pass an empty string as a valid UUID, as it doesn't
+ * strictly meet the formatting requirements. parse_uuid will accept an
+ * empty string and zero out the uuid struct accordingly.
+ * - parse_uuid does additional semantic checks on clock_seq_hi_and_reserved
+ * that validate_uuid will not do.
+ * validate_uuid is intended to strictly check that it's a well-formed uuid.
+int validate_uuid(const char *, size_t, struct uuid *);
int parse_uuid(const char *, struct uuid *);
int uuidcmp(const struct uuid *, const struct uuid *);