All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joshua Brindle <method@manicmethod.com>
To: Karl MacMillan <karlwmacmillan@gmail.com>
Cc: SE Linux <selinux@tycho.nsa.gov>
Subject: Re: [PATCH] Sepolgen: improve parser error recovery
Date: Thu, 18 Mar 2010 16:18:44 -0400	[thread overview]
Message-ID: <4BA28AA4.7000605@manicmethod.com> (raw)
In-Reply-To: <10143821003121157o2ccc5c2cw2079b86d86c33ef@mail.gmail.com>

Karl MacMillan wrote:
> Sepolgen has long not recovered from parsing errors, leading to
> a blacklist of none bad modules in the source. I finally tracked
> down the problem (lexer state) and this patch fixes the problem
> by causing the lexer to be rebuilt on error.
> ---

So do the modules that were blacklisted still fail to parse and this 
just handles it by reinitializing the lexer and parser?

>   sepolgen/src/sepolgen/refparser.py |   28 ++++++++++++----------------
>   1 files changed, 12 insertions(+), 16 deletions(-)
>
> diff --git a/sepolgen/src/sepolgen/refparser.py
> b/sepolgen/src/sepolgen/refparser.py
> index 23beb39..5c5093c 100644
> --- a/sepolgen/src/sepolgen/refparser.py
> +++ b/sepolgen/src/sepolgen/refparser.py
> @@ -279,7 +279,7 @@ parse_file = ""
>   #     refpolicy.SupportMacros and should always be present during parsing
>   #     though it may not contain any macros.
>   spt = None
> -success=True
> +success = True
>
>   # utilities
>   def collect(stmts, parent, val=None):
> @@ -921,9 +921,7 @@ def p_optional_semi(p):
>   #
>
>   def p_error(tok):
> -    global error
> -    global parse_file
> -    global success
> +    global error, parse_file, success, parser
>       error = "%s: Syntax error on line %d %s [type=%s]" % (parse_file,
> tok.lineno, tok.value, tok.type)
>       print error
>       success = False
> @@ -939,6 +937,7 @@ parser = None
>   lexer = None
>   def create_globals(module, support, debug):
>       global parser, lexer, m, spt
> +
>       if not parser:
>           lexer = lex.lex()
>           parser = yacc.yacc(method="LALR", debug=debug, write_tables=0)
> @@ -955,17 +954,20 @@ def create_globals(module, support, debug):
>
>   def parse(text, module=None, support=None, debug=False):
>       create_globals(module, support, debug)
> -    lexer.lexdata = []
> -    lexer.lexpos = 0
> -    lexer.lineno = 1
> +    global error, parser, lexer, success
> +
> +    success = True
>
>       try:
> -        parser.parse(text, debug=debug)
> +        parser.parse(text, debug=debug, lexer=lexer)
>       except Exception, e:
> -        global error
> +        parser = None
> +        lexer = None
>           error = "internal parser error: %s" % str(e) + "\n" +
> traceback.format_exc()
>
> -    if error is not None:
> +    if not success:
> +        # force the parser and lexer to be rebuilt - we have some
> problems otherwise
> +        parser = None
>           msg = 'could not parse text: "%s"' % error
>           raise ValueError(msg)
>       return m
> @@ -973,15 +975,9 @@ def parse(text, module=None, support=None, debug=False):
>   def list_headers(root):
>       modules = []
>       support_macros = None
> -    blacklist = ["init.if", "inetd.if", "uml.if", "thunderbird.if"]
>
>       for dirpath, dirnames, filenames in os.walk(root):
>           for name in filenames:
> -            # FIXME: these make the parser barf in various
> unrecoverable ways, so we must skip
> -            # them.
> -            if name in blacklist:
> -                continue
> -
>               modname = os.path.splitext(name)
>               filename = os.path.join(dirpath, name)
>
> --
> 1.6.6
>
> --
> This message was distributed to subscribers of the selinux mailing list.
> If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
> the words "unsubscribe selinux" without quotes as the message.
>

--
This message was distributed to subscribers of the selinux mailing list.
If you no longer wish to subscribe, send mail to majordomo@tycho.nsa.gov with
the words "unsubscribe selinux" without quotes as the message.

  reply	other threads:[~2010-03-18 20:18 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-12 19:57 [PATCH] Sepolgen: improve parser error recovery Karl MacMillan
2010-03-18 20:18 ` Joshua Brindle [this message]
2010-03-22 13:58   ` Karl MacMillan
2010-03-22 14:26     ` Joshua Brindle
2010-03-23 15:32       ` Karl MacMillan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4BA28AA4.7000605@manicmethod.com \
    --to=method@manicmethod.com \
    --cc=karlwmacmillan@gmail.com \
    --cc=selinux@tycho.nsa.gov \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.