On 11/8/19 10:07 AM, Eric Blake wrote:
On 11/8/19 8:40 AM, Philippe Mathieu-Daudé wrote:
Since not all trace backends support dynamic field width in
format (dtrace via stap does not), forbid them.

Add a check to refuse field width in new formats:


+++ b/scripts/tracetool/__init__.py
@@ -206,6 +206,7 @@ class Event(object):
                        "\s*"
                        "(?:(?:(?P<fmt_trans>\".+),)?\s*(?P<fmt>\".+))?"
                        "\s*")
+    _DFWRE = re.compile(".*(%0?\*).*")

The use of leading and trailing .* is pointless if the RE itself is used unanchored and where you only care if the () matched.

Following up on this (based on an IRC conversation):

re.match _is_ anchored by default, while re.search is unanchored


This doesn't catch all valid uses of * in a printf format.  Better might be something like:

_DFWRE = re.compile("%[\d\.\- +#']*\*")

which matches only if there is a %, any number of characters that can form a printf flag, as well as a numeric field width but dynamic precision.


+        if Event._DFWRE.match(fmt):

Or put differently, if you want to drop the .* from the compiled regex, then you need to use .search(fmt) here rather than .match(fmt).

--
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org


Reply via email to