mirror of
git://sourceware.org/git/lvm2.git
synced 2025-01-02 01:18:26 +03:00
libdm: prevent empty config file section names
Change c353949597
to use existing
_dup_string_tok(). alloca() doesn't fail cleanly (and needs
replacing.)
This commit is contained in:
parent
76ca82df82
commit
b6d3fd62fc
@ -1,5 +1,6 @@
|
|||||||
Version 1.02.84 -
|
Version 1.02.84 -
|
||||||
====================================
|
====================================
|
||||||
|
Allow section names in config file data to be quoted strings.
|
||||||
Close fifos before exiting in dmeventd restart() error path.
|
Close fifos before exiting in dmeventd restart() error path.
|
||||||
Move printf format string directly into dm_asprintf args list.
|
Move printf format string directly into dm_asprintf args list.
|
||||||
Catch invalid use of string sort values when reporting numerical fields.
|
Catch invalid use of string sort values when reporting numerical fields.
|
||||||
|
@ -253,11 +253,7 @@ static int _write_value(struct config_output *out, const struct dm_config_value
|
|||||||
|
|
||||||
switch (v->type) {
|
switch (v->type) {
|
||||||
case DM_CFG_STRING:
|
case DM_CFG_STRING:
|
||||||
if (!(buf = alloca(dm_escaped_len(v->v.str)))) {
|
buf = alloca(dm_escaped_len(v->v.str));
|
||||||
log_error("temporary stack allocation for a config "
|
|
||||||
"string failed");
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
line_append("\"%s\"", dm_escape_double_quotes(buf, v->v.str));
|
line_append("\"%s\"", dm_escape_double_quotes(buf, v->v.str));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -440,24 +436,40 @@ static struct dm_config_node *_file(struct parser *p)
|
|||||||
static struct dm_config_node *_section(struct parser *p)
|
static struct dm_config_node *_section(struct parser *p)
|
||||||
{
|
{
|
||||||
/* IDENTIFIER SECTION_B_CHAR VALUE* SECTION_E_CHAR */
|
/* IDENTIFIER SECTION_B_CHAR VALUE* SECTION_E_CHAR */
|
||||||
|
|
||||||
struct dm_config_node *root, *n, *l = NULL;
|
struct dm_config_node *root, *n, *l = NULL;
|
||||||
char *token;
|
char *str;
|
||||||
|
|
||||||
if (!(root = _create_node(p->mem))) {
|
if (!(root = _create_node(p->mem))) {
|
||||||
log_error("Failed to allocate section node");
|
log_error("Failed to allocate section node");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!(root->key = token = _dup_tok(p)))
|
|
||||||
return_NULL;
|
|
||||||
|
|
||||||
if (p->t == TOK_STRING_ESCAPED) {
|
if (p->t == TOK_STRING_ESCAPED) {
|
||||||
token ++; /* OK as the token is pool-allocated */
|
if (!(str = _dup_string_tok(p)))
|
||||||
token[strlen(token) - 1] = 0;
|
return_NULL;
|
||||||
dm_unescape_double_quotes(token);
|
dm_unescape_double_quotes(str);
|
||||||
root->key = token;
|
root->key = str;
|
||||||
|
|
||||||
match(TOK_STRING_ESCAPED);
|
match(TOK_STRING_ESCAPED);
|
||||||
} else
|
} else if (p->t == TOK_STRING) {
|
||||||
|
if (!(str = _dup_string_tok(p)))
|
||||||
|
return_NULL;
|
||||||
|
root->key = str;
|
||||||
|
|
||||||
|
match(TOK_STRING);
|
||||||
|
} else {
|
||||||
|
if (!(root->key = _dup_tok(p)))
|
||||||
|
return_NULL;
|
||||||
|
|
||||||
match(TOK_IDENTIFIER);
|
match(TOK_IDENTIFIER);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!strlen(root->key)) {
|
||||||
|
log_error("Parse error at byte %" PRIptrdiff_t " (line %d): empty section identifier",
|
||||||
|
p->tb - p->fb + 1, p->line);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
if (p->t == TOK_SECTION_B) {
|
if (p->t == TOK_SECTION_B) {
|
||||||
match(TOK_SECTION_B);
|
match(TOK_SECTION_B);
|
||||||
|
Loading…
Reference in New Issue
Block a user