mirror of
https://github.com/esphome/esphome.git
synced 2026-10-15 02:32:49 +00:00
[core] Let the scanf buffer argument contain a call with commas
This commit is contained in:
@@ -23,9 +23,10 @@ from esphome.types import ConfigType
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
# The string literal handed to a scanf family call as its format: an optional
|
||||
# first argument (sscanf/fscanf, possibly a literal itself) then the literal.
|
||||
# first argument (sscanf/fscanf; a literal or a call with its own commas is
|
||||
# fine) then the literal.
|
||||
_SCANF_FORMAT_RE = re.compile(
|
||||
r'scanf\s*\((?:(?:"(?:[^"\\]|\\.)*"|[^,;"])*,)?\s*"((?:[^"\\]|\\.)*)"'
|
||||
r'scanf\s*\((?:(?:"(?:[^"\\]|\\.)*"|\([^()]*\)|[^,;"()])*,)?\s*"((?:[^"\\]|\\.)*)"'
|
||||
)
|
||||
# Standard scanf float conversions %f %F %e %E %g %G %a %A with optional
|
||||
# suppression, width and length; also the invalid %.2f users write by analogy
|
||||
|
||||
@@ -43,6 +43,9 @@ from esphome.types import ConfigType
|
||||
# Escaped quotes, nested calls, a ')' inside the format, an unterminated call
|
||||
('sscanf(buf, "\\"%f\\"", &v)', True),
|
||||
('sscanf(f(x), "%f", &v)', True),
|
||||
('sscanf(s.substr(0, 2).c_str(), "%f", &v)', True),
|
||||
('sscanf(strtok(s, ","), "%f", &v)', True),
|
||||
('sscanf(strtok(s, ","), "%d", &v)', False),
|
||||
('sscanf(buf, "%d)", &a); g("%f")', False),
|
||||
('sscanf(buf, "%d", &a; g("%f")', False),
|
||||
('sscanf(buf, "%f"', True),
|
||||
|
||||
Reference in New Issue
Block a user