From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56207) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZIbM1-0001Fy-5B for qemu-devel@nongnu.org; Fri, 24 Jul 2015 07:41:30 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZIbLw-0001me-2p for qemu-devel@nongnu.org; Fri, 24 Jul 2015 07:41:29 -0400 Received: from mx1.redhat.com ([209.132.183.28]:50271) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZIbLv-0001m8-UD for qemu-devel@nongnu.org; Fri, 24 Jul 2015 07:41:24 -0400 From: Markus Armbruster References: <1435782155-31412-1-git-send-email-armbru@redhat.com> <1435782155-31412-6-git-send-email-armbru@redhat.com> <55AD36A1.6050405@redhat.com> Date: Fri, 24 Jul 2015 13:41:20 +0200 In-Reply-To: <55AD36A1.6050405@redhat.com> (Eric Blake's message of "Mon, 20 Jul 2015 11:57:53 -0600") Message-ID: <87egjx4wbj.fsf@blackfin.pond.sub.org> MIME-Version: 1.0 Content-Type: text/plain Subject: Re: [Qemu-devel] [PATCH RFC v2 05/47] qapi: Reject -p arguments that break qapi-event.py List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: kwolf@redhat.com, berto@igalia.com, qemu-devel@nongnu.org, mdroth@linux.vnet.ibm.com Eric Blake writes: > On 07/01/2015 02:21 PM, Markus Armbruster wrote: >> qapi-event.py breaks when you ask for a funny prefix like '@'. >> Protect it. > > Only possible from the command line (not triggered by our makefiles); > but doesn't hurt. > >> >> Signed-off-by: Markus Armbruster >> --- >> scripts/qapi.py | 6 ++++++ >> 1 file changed, 6 insertions(+) > > >> >> diff --git a/scripts/qapi.py b/scripts/qapi.py >> index 2bbc8ff..ea94ce5 100644 >> --- a/scripts/qapi.py >> +++ b/scripts/qapi.py >> @@ -1003,6 +1003,12 @@ def parse_command_line(extra_options = "", extra_long_options = []): >> for oa in opts: >> o, a = oa >> if o in ("-p", "--prefix"): >> + match = re.match('([A-Za-z_.-][A-Za-z0-9_.-]*)?', a) > > I can understand allowing a leading _, but why bother allowing a leading > '.' or '-'? Those will get normalized to _, but in all honesty, no one > should ever be doing that. My patch rejects exactly the prefixes that won't work. > I'd be just as happy with the shorter: > > match = re.match('([A-Za-z_][A-Za-z0-9_.-]*)?', a) This additionally rejects a few rather foolish ones. I have a slight preference for the tool staying out of policing foolish prefixes. >> + if match.end() != len(a): >> + print >>sys.stderr, \ >> + "%s: 'funny character '%s' in argument of -prefix" \ > > 'qemu' is unusual for accepting -single-dash-long-opts; I don't think > python getopts does the same by default. Please spell this error > message --prefix. Typo, will fix. >> + % (sys.argv[0], a[match.end()]) >> + sys.exit(1) >> prefix = a >> elif o in ("-o", "--output-dir"): >> output_dir = a + "/" >> > > With the second spelling fix, and optionally with the shorter regex, > > Reviewed-by: Eric Blake Thanks!