From b548233f3323b1002418fa6f9c32254ed1e33abd Mon Sep 17 00:00:00 2001 From: Luiz Augusto von Dentz Date: Tue, 12 Dec 2017 13:55:07 -0200 Subject: [PATCH] monitor: Detect string format User may enter UUID in string format other then 128 bits. --- monitor/uuid.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/monitor/uuid.c b/monitor/uuid.c index 9839d03be..bc638a2f3 100644 --- a/monitor/uuid.c +++ b/monitor/uuid.c @@ -27,6 +27,7 @@ #endif #include +#include #include #include "uuid.h" @@ -735,12 +736,28 @@ const char *uuid32_to_str(uint32_t uuid) const char *uuidstr_to_str(const char *uuid) { uint32_t val; + size_t len; int i; if (!uuid) return NULL; - if (strlen(uuid) != 36) + len = strlen(uuid); + + if (len < 36) { + char *endptr = NULL; + + val = strtol(uuid, &endptr, 0); + if (!endptr || *endptr != '\0') + return NULL; + + if (val > UINT16_MAX) + return uuid32_to_str(val); + + return uuid16_to_str(val); + } + + if (len != 36) return NULL; for (i = 0; uuid128_table[i].str; i++) { -- 2.47.3