diff --git a/sys/geom/label/g_label.c b/sys/geom/label/g_label.c index c37ca3511890..13639aedf7b2 100644 --- a/sys/geom/label/g_label.c +++ b/sys/geom/label/g_label.c @@ -179,9 +179,25 @@ g_label_mangle_name(char *label, size_t size) { struct sbuf *sb; const u_char *c; + size_t len, i; + + /* Trim trailing whitespace. */ + len = strlen(label); + for (i = len; i > 0; i--) { + if (isspace(label[i - 1])) + label[i - 1] = '\0'; + else + break; + } + if (*label == '\0') + return; + sb = sbuf_new(NULL, NULL, size, SBUF_FIXEDLEN); for (c = label; *c != '\0'; c++) { + /* Trim leading whitespace. */ + if (isspace(*c) && sbuf_len(sb) == 0) + continue; if (!isprint(*c) || isspace(*c) || *c =='"' || *c == '%') sbuf_printf(sb, "%%%02X", *c); else