Page MenuHomePhabricator

libvyosconfig parser does not support escaped quotes inside single-quoted strings
Closed, ResolvedPublicBUG

Description

The parser from libvyosconfig used in vyos.configtree supports escaped quotes (single and double) in double-quoted strings, but trying to use them in a single-quoted string causes a parse error.

>>> c = vyos.configtree.ConfigTree(""" foo "fo\\'\\"o"  """)
>>> print(str(c))
foo "fo'\"o"

 
>>> c = vyos.configtree.ConfigTree(""" foo 'fo\\'\\"o'  """)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python3/dist-packages/vyos/configtree.py", line 167, in __init__
    raise ValueError("Failed to parse config: {0}".format(msg))
ValueError: Failed to parse config: String is not terminated

This is really a lexer rather than a parser issue, it emits two tokens (STRING and IDENT) rather than one in that case.

While existing VyOS code always uses double quotes in config output, people with hand-edited configs can run into confusing errors.

Details

Difficulty level
Unknown (require assessment)
Version
1.2.0
Why the issue appeared?
Will be filled on close

Event Timeline

dmbaturin changed the task status from Open to Needs testing.Jun 29 2019, 9:44 PM
pasik added a subscriber: pasik.Jul 2 2019, 3:29 PM
syncer triaged this task as Low priority.Aug 31 2019, 12:04 AM
syncer edited projects, added VyOS 1.3 Equuleus; removed VyOS 1.2 Crux.
dmbaturin closed this task as Resolved.Sep 6 2019, 5:00 PM
dmbaturin claimed this task.
c-po moved this task from Need Triage to Finished on the VyOS 1.3 Equuleus board.Sun, Oct 13, 3:05 PM