qemu-trivial
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 3/3] trace: Forbid dynamic field width in event format


From: Eric Blake
Subject: Re: [PATCH v2 3/3] trace: Forbid dynamic field width in event format
Date: Mon, 18 Nov 2019 12:42:25 -0600
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.1.1

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

[Prev in Thread] Current Thread [Next in Thread]