Author: lulf
Date: Sun Jul 19 12:57:10 2009
New Revision: 195759
URL: http://svn.freebsd.org/changeset/base/195759

Log:
  MFC r194924:
  
  - Apply the same naming rules of LVM names as done in the LVM code itself.
  
  PR:           kern/135874

Modified:
  stable/7/sys/   (props changed)
  stable/7/sys/contrib/pf/   (props changed)
  stable/7/sys/geom/linux_lvm/g_linux_lvm.c

Modified: stable/7/sys/geom/linux_lvm/g_linux_lvm.c
==============================================================================
--- stable/7/sys/geom/linux_lvm/g_linux_lvm.c   Sat Jul 18 21:50:53 2009        
(r195758)
+++ stable/7/sys/geom/linux_lvm/g_linux_lvm.c   Sun Jul 19 12:57:10 2009        
(r195759)
@@ -826,14 +826,6 @@ llvm_md_decode(const u_char *data, struc
        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, struc
                        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 b
        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 b
        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
 {
        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
        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
        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
        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
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to