1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-11 09:50:12 +00:00

- Apply the same naming rules of LVM names as done in the LVM code itself.

PR:		kern/135874
This commit is contained in:
Ulf Lilleengen 2009-06-24 22:09:30 +00:00
parent 499650a033
commit ac2a008e69
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=194924

View File

@ -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 @@ llvm_textconf_decode_sg(char **buf, char *tok, struct g_llvm_lv *lv)
free(sg, M_GLLVM);
return (-1);
}
#undef GRAB_NAME
#undef GRAB_INT
#undef GRAB_STR
#undef SPLIT