Skip to contentSkip to conversation

sepolgen: Reset line numbers when parsing files

PATCH Applied Nicolas Iooss 2 participants 2 messages Oct 24, 2015 – Oct 27, 2015 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sepolgen: Reset line numbers when parsing files

When running sepolgen-ifgen on refpolicy (git master branch), the following messages show up:

/usr/share/selinux/refpolicy/include/kernel/selinux.if: Syntax error on line 3369 gen_context [type=GEN_CONTEXT] /usr/share/selinux/refpolicy/include/system/init.if: Syntax error on line 188379 ' [type=SQUOTE] /usr/share/selinux/refpolicy/include/system/init.if: Syntax error on line 188385 ' [type=SQUOTE]

The line numbers are incorrect because the lineno member of the lexer object is not resetted after each file has been processed. After fixing this, the messages are nicer:

/usr/share/selinux/refpolicy/include/kernel/selinux.if: Syntax error on line 43 gen_context [type=GEN_CONTEXT] /usr/share/selinux/refpolicy/include/system/init.if: Syntax error on line 1416 ' [type=SQUOTE] /usr/share/selinux/refpolicy/include/system/init.if: Syntax error on line 1422 ' [type=SQUOTE]

As line 43 of kernel/selinux.if contains a genfscon statement with a gen_context component, the reported line numbers are now correct.

---
 sepolgen/src/sepolgen/refparser.py | 1 +
 1 file changed, 1 insertion(+)
sepolgen/src/sepolgen/refparser.py +1 -0
index b50112ccd900..3132c6fe7109 100644
@@ -1003,6 +1003,7 @@ def parse(text, module=None, support=None, debug=False):
     create_globals(module, support, debug)
     global error, parser, lexer, success
 
+    lexer.lineno = 1
     success = True
 
     try:
Signature · 1 line
2.6.2
#1 lore raw
Quoted 21 lines · Nicolas Iooss

When running sepolgen-ifgen on refpolicy (git master branch), the following messages show up:

/usr/share/selinux/refpolicy/include/kernel/selinux.if: Syntax error on line 3369 gen_context [type=GEN_CONTEXT] /usr/share/selinux/refpolicy/include/system/init.if: Syntax error on line 188379 ' [type=SQUOTE] /usr/share/selinux/refpolicy/include/system/init.if: Syntax error on line 188385 ' [type=SQUOTE]

The line numbers are incorrect because the lineno member of the lexer object is not resetted after each file has been processed. After fixing this, the messages are nicer:

/usr/share/selinux/refpolicy/include/kernel/selinux.if: Syntax error on line 43 gen_context [type=GEN_CONTEXT] /usr/share/selinux/refpolicy/include/system/init.if: Syntax error on line 1416 ' [type=SQUOTE] /usr/share/selinux/refpolicy/include/system/init.if: Syntax error on line 1422 ' [type=SQUOTE]

Quoted 4 lines

As line 43 of kernel/selinux.if contains a genfscon statement with a gen_context component, the reported line numbers are now correct.

Thanks, applied.

Quoted 17 lines
---
  sepolgen/src/sepolgen/refparser.py | 1 +
  1 file changed, 1 insertion(+)
sepolgen/src/sepolgen/refparser.py +1 -0
index b50112ccd900..3132c6fe7109 100644
@@ -1003,6 +1003,7 @@ def parse(text, module=None, support=None, debug=False):
      create_globals(module, support, debug)
      global error, parser, lexer, success
 
+    lexer.lineno = 1
      success = True
 
      try: