[master] 9a64ba9 vmodtool: enforce function and argument names be valid c symbols
Nils Goroll
nils.goroll at uplex.de
Thu Dec 21 17:42:06 UTC 2017
commit 9a64ba93badcee6bc46fc98c84a49b862053548a
Author: Nils Goroll <nils.goroll at uplex.de>
Date: Thu Dec 21 18:39:43 2017 +0100
vmodtool: enforce function and argument names be valid c symbols
diff --git a/lib/libvcc/vmodtool.py b/lib/libvcc/vmodtool.py
index f870e69..6400d4d 100755
--- a/lib/libvcc/vmodtool.py
+++ b/lib/libvcc/vmodtool.py
@@ -310,6 +310,8 @@ def arg(txt):
return a, s
+def nmlegal(nm):
+ return re.match('^[a-zA-Z0-9_]+$', nm)
# XXX cant have ( or ) in an argument default value
class prototype(object):
@@ -332,6 +334,8 @@ class prototype(object):
i = s.find("(")
assert i > 0
self.name = prefix + s[:i].strip()
+ if not nmlegal(self.cname()):
+ err("%s(): Illegal name\n" % self.name, warn=False)
s = s[i:].strip()
assert s[0] == "("
assert s[-1] == ")"
@@ -340,10 +344,14 @@ class prototype(object):
names = {}
while len(s) > 0:
a, s = arg(s)
- if a.nm is not None and a.nm in names:
- err("%s(): duplicate argument name '%s'\n" % (self.name, a.nm),
- warn=False)
- names[a.nm] = True
+ if a.nm is not None:
+ if not nmlegal(a.nm):
+ err("%s(): illegal argument name '%s'\n"
+ % (self.name, a.nm), warn=False)
+ if a.nm in names:
+ err("%s(): duplicate argument name '%s'\n"
+ % (self.name, a.nm), warn=False)
+ names[a.nm] = True
self.args.append(a)
s = s.lstrip()
if len(s) == 0:
More information about the varnish-commit
mailing list