mirror of
git://sourceware.org/git/lvm2.git
synced 2025-03-06 00:58:48 +03:00
systemid: Require alphanumeric 1st character.
Require system ID to begin with an alphanumeric character. Rename fn to make clear it's only validation for systemid and always terminate result rather than imposing this on the caller.
This commit is contained in:
parent
a5df78e0f0
commit
0551d1c56e
@ -65,7 +65,7 @@ char *system_id_from_string(struct cmd_context *cmd, const char *str)
|
||||
if (!(system_id = dm_pool_zalloc(cmd->mem, strlen(str) + 1)))
|
||||
return NULL;
|
||||
|
||||
copy_valid_chars(str, system_id);
|
||||
copy_systemid_chars(str, system_id);
|
||||
|
||||
if (!system_id[0])
|
||||
return NULL;
|
||||
|
@ -102,46 +102,36 @@ int validate_name(const char *n)
|
||||
}
|
||||
|
||||
/*
|
||||
* Copy valid characters from source to destination.
|
||||
* Copy valid systemid characters from source to destination.
|
||||
* Invalid characters are skipped. Copying is stopped
|
||||
* when NAME_LEN characters have been copied.
|
||||
* A terminating NUL is appended.
|
||||
*/
|
||||
|
||||
void copy_valid_chars(const char *src, char *dst)
|
||||
void copy_systemid_chars(const char *src, char *dst)
|
||||
{
|
||||
const char *s = src;
|
||||
char *d = dst;
|
||||
int len = 0;
|
||||
int i;
|
||||
char c;
|
||||
|
||||
if (!s || !*s)
|
||||
return;
|
||||
|
||||
/* Omit leading hypens. */
|
||||
for (i = 0; i < strlen(src); i++) {
|
||||
c = *s;
|
||||
if (c != '-')
|
||||
break;
|
||||
/* Skip non-alphanumeric starting characters */
|
||||
while (*s && !isalnum(*s))
|
||||
s++;
|
||||
}
|
||||
|
||||
for (i = 0; i < strlen(src); i++) {
|
||||
c = *s;
|
||||
|
||||
if (!isalnum(c) && c != '.' && c != '_' && c != '-' && c != '+') {
|
||||
s++;
|
||||
while ((c = *s++)) {
|
||||
if (!isalnum(c) && c != '.' && c != '_' && c != '-' && c != '+')
|
||||
continue;
|
||||
}
|
||||
|
||||
*d = *s;
|
||||
d++;
|
||||
s++;
|
||||
len++;
|
||||
*d++ = c;
|
||||
|
||||
if (len == NAME_LEN)
|
||||
if (++len >= NAME_LEN)
|
||||
break;
|
||||
}
|
||||
|
||||
*d = '\0';
|
||||
}
|
||||
|
||||
static const char *_lvname_has_reserved_prefix(const char *lvname)
|
||||
|
@ -44,7 +44,7 @@ int validate_name(const char *n);
|
||||
name_error_t validate_name_detailed(const char *n);
|
||||
int validate_tag(const char *n);
|
||||
|
||||
void copy_valid_chars(const char *src, char *dst);
|
||||
void copy_systemid_chars(const char *src, char *dst);
|
||||
|
||||
int apply_lvname_restrictions(const char *name);
|
||||
int is_reserved_lvname(const char *name);
|
||||
|
Loading…
x
Reference in New Issue
Block a user