summaryrefslogtreecommitdiffstats
path: root/sys/geom/linux_lvm
diff options
context:
space:
mode:
authorlulf <lulf@FreeBSD.org>2009-06-24 22:09:30 +0000
committerlulf <lulf@FreeBSD.org>2009-06-24 22:09:30 +0000
commit380cb58248d7b11a8c1fb74bfdcf50a0201ac3a9 (patch)
tree8904d27aa56aca0b64e223a908851fed54883065 /sys/geom/linux_lvm
parent3a4b2dc4d4ceeae550d1068d15c397bd098e73ca (diff)
downloadFreeBSD-src-380cb58248d7b11a8c1fb74bfdcf50a0201ac3a9.zip
FreeBSD-src-380cb58248d7b11a8c1fb74bfdcf50a0201ac3a9.tar.gz
- Apply the same naming rules of LVM names as done in the LVM code itself.
PR: kern/135874
Diffstat (limited to 'sys/geom/linux_lvm')
-rw-r--r--sys/geom/linux_lvm/g_linux_lvm.c43
1 files changed, 27 insertions, 16 deletions
diff --git a/sys/geom/linux_lvm/g_linux_lvm.c b/sys/geom/linux_lvm/g_linux_lvm.c
index 5f0db7a..d210611 100644
--- a/sys/geom/linux_lvm/g_linux_lvm.c
+++ b/sys/geom/linux_lvm/g_linux_lvm.c
@@ -826,14 +826,6 @@ llvm_md_decode(const u_char *data, struct g_llvm_metadata *md,
return (0);
}
-#define GRAB_NAME(tok, name, len) \
- len = 0; \
- while (tok[len] && (isalpha(tok[len]) || isdigit(tok[len])) && \
- len < G_LLVM_NAMELEN - 1) \
- len++; \
- bcopy(tok, name, len); \
- name[len] = '\0';
-
#define GRAB_INT(key, tok1, tok2, v) \
if (tok1 && tok2 && strncmp(tok1, key, sizeof(key)) == 0) { \
v = strtol(tok2, &tok1, 10); \
@@ -864,6 +856,27 @@ llvm_md_decode(const u_char *data, struct g_llvm_metadata *md,
break; \
}
+static size_t
+llvm_grab_name(char *name, const char *tok)
+{
+ size_t len;
+
+ len = 0;
+ if (tok == NULL)
+ return (0);
+ if (tok[0] == '-')
+ return (0);
+ if (strcmp(tok, ".") == 0 || strcmp(tok, "..") == 0)
+ return (0);
+ while (tok[len] && (isalpha(tok[len]) || isdigit(tok[len]) ||
+ tok[len] == '.' || tok[len] == '_' || tok[len] == '-' ||
+ tok[len] == '+') && len < G_LLVM_NAMELEN - 1)
+ len++;
+ bcopy(tok, name, len);
+ name[len] = '\0';
+ return (len);
+}
+
static int
llvm_textconf_decode(u_char *data, int buflen, struct g_llvm_metadata *md)
{
@@ -872,7 +885,7 @@ llvm_textconf_decode(u_char *data, int buflen, struct g_llvm_metadata *md)
char *tok, *v;
char name[G_LLVM_NAMELEN];
char uuid[G_LLVM_UUIDLEN];
- int len;
+ size_t len;
if (buf == NULL || *buf == '\0')
return (EINVAL);
@@ -880,7 +893,7 @@ llvm_textconf_decode(u_char *data, int buflen, struct g_llvm_metadata *md)
tok = strsep(&buf, "\n");
if (tok == NULL)
return (EINVAL);
- GRAB_NAME(tok, name, len);
+ len = llvm_grab_name(name, tok);
if (len == 0)
return (EINVAL);
@@ -970,7 +983,7 @@ llvm_textconf_decode_pv(char **buf, char *tok, struct g_llvm_vg *vg)
{
struct g_llvm_pv *pv;
char *v;
- int len;
+ size_t len;
if (*buf == NULL || **buf == '\0')
return (EINVAL);
@@ -983,7 +996,7 @@ llvm_textconf_decode_pv(char **buf, char *tok, struct g_llvm_vg *vg)
len = 0;
if (tok == NULL)
goto bad;
- GRAB_NAME(tok, pv->pv_name, len);
+ len = llvm_grab_name(pv->pv_name, tok);
if (len == 0)
goto bad;
@@ -1024,7 +1037,7 @@ llvm_textconf_decode_lv(char **buf, char *tok, struct g_llvm_vg *vg)
struct g_llvm_lv *lv;
struct g_llvm_segment *sg;
char *v;
- int len;
+ size_t len;
if (*buf == NULL || **buf == '\0')
return (EINVAL);
@@ -1036,10 +1049,9 @@ llvm_textconf_decode_lv(char **buf, char *tok, struct g_llvm_vg *vg)
lv->lv_vg = vg;
LIST_INIT(&lv->lv_segs);
- len = 0;
if (tok == NULL)
goto bad;
- GRAB_NAME(tok, lv->lv_name, len);
+ len = llvm_grab_name(lv->lv_name, tok);
if (len == 0)
goto bad;
@@ -1162,7 +1174,6 @@ bad:
free(sg, M_GLLVM);
return (-1);
}
-#undef GRAB_NAME
#undef GRAB_INT
#undef GRAB_STR
#undef SPLIT
OpenPOWER on IntegriCloud