1
0
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:
Alasdair G Kergon 2015-02-23 19:47:03 +00:00
parent a5df78e0f0
commit 0551d1c56e
3 changed files with 13 additions and 23 deletions

View File

@ -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;

View File

@ -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)

View File

@ -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);