Commit c7fec8a9 authored by Konrad Sztyber's avatar Konrad Sztyber Committed by Tomasz Zawadzki
Browse files

util: forbid empty strings in spdk_uuid_parse() on FreeBSD



uuid_from_string() differs from uuid_parse() in the way it handles empty
strings: the former succeeds and returns a NULL UUID, while the latter
treats is an error and returns non-zero exit code.  So, to keep the
behavior consistent between Linux and FreeBSD, an extra check was added
to forbid passing empty strings under FreeBSD.

Signed-off-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Change-Id: I0ceb397f7614a71e50859467f968f3b4c6978964
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/20534


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarTomasz Zawadzki <tomasz.zawadzki@intel.com>
Reviewed-by: default avatarJim Harris <jim.harris@samsung.com>
parent 75b68561
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -75,6 +75,15 @@ spdk_uuid_parse(struct spdk_uuid *uuid, const char *uuid_str)
{
	uint32_t status;

	/* uuid_from_string() differs from uuid_parse() in the way it handles empty strings: the
	 * former succeeds and returns a NULL UUID, while the latter treats is an error and returns
	 * non-zero exit code.  So, to keep the behavior consistent between Linux and FreeBSD, we
	 * explicitly check for an empty string here.
	 */
	if (strlen(uuid_str) == 0) {
		return -EINVAL;
	}

	uuid_from_string(uuid_str, (uuid_t *)uuid, &status);

	return status == 0 ? 0 : -EINVAL;