diff --git a/device_mapper/libdm-config.c b/device_mapper/libdm-config.c index 1c1d6d9d0..9944f47ab 100644 --- a/device_mapper/libdm-config.c +++ b/device_mapper/libdm-config.c @@ -592,6 +592,8 @@ static struct dm_config_node *_section(struct parser *p, struct dm_config_node * struct dm_config_node *root; struct dm_config_value *value; char *str; + size_t len; + char buf[8192]; if (p->t == TOK_STRING_ESCAPED) { if (!(str = _dup_string_tok(p))) @@ -605,9 +607,16 @@ static struct dm_config_node *_section(struct parser *p, struct dm_config_node * match(TOK_STRING); } else { - if (!(str = _dup_tok(p))) - return_NULL; - + len = p->te - p->tb; + if (len < (sizeof(buf) - 1)) { + /* Use stack for smaller string */ + str = buf; + memcpy(str, p->tb, len); + str[len] = '\0'; + } else { + if (!(str = _dup_tok(p))) + return_NULL; + } match(TOK_IDENTIFIER); }