gixy icon indicating copy to clipboard operation
gixy copied to clipboard

Crashes on empty conf.d directory

Open WileESpaghetti opened this issue 7 years ago • 3 comments

I have the default Ubuntu nginx.conf that contains the line include /etc/nginx/conf.d/*.conf; For me that directory happens to be empty and this causes gixy to crash.

I would either expect it ignore the empty directory or have an additional analysis rule that will flag that as an error or warning.

Here's the stack trace

[nginx_parser]  WARNING File not found: /etc/nginx/conf.d/*.conf
Traceback (most recent call last):
  File "/usr/local/bin/gixy", line 11, in <module>
    sys.exit(main())
  File "/usr/local/lib/python2.7/dist-packages/gixy/cli/main.py", line 153, in main
    yoda.audit(path)
  File "/usr/local/lib/python2.7/dist-packages/gixy/core/manager.py", line 24, in audit
    self._audit_recursive(self.root.children)
  File "/usr/local/lib/python2.7/dist-packages/gixy/core/manager.py", line 39, in _audit_recursive
    self._audit_recursive(directive.children)
  File "/usr/local/lib/python2.7/dist-packages/gixy/core/manager.py", line 39, in _audit_recursive
    self._audit_recursive(directive.children)
  File "/usr/local/lib/python2.7/dist-packages/gixy/core/manager.py", line 39, in _audit_recursive
    self._audit_recursive(directive.children)
  File "/usr/local/lib/python2.7/dist-packages/gixy/core/manager.py", line 39, in _audit_recursive
    self._audit_recursive(directive.children)
  File "/usr/local/lib/python2.7/dist-packages/gixy/core/manager.py", line 34, in _audit_recursive
    self._update_variables(directive)
  File "/usr/local/lib/python2.7/dist-packages/gixy/core/manager.py", line 49, in _update_variables
    for var in directive.variables:
  File "/usr/local/lib/python2.7/dist-packages/cached_property.py", line 26, in __get__
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "/usr/local/lib/python2.7/dist-packages/gixy/directives/block.py", line 119, in variables
    for name, group in regexp.groups.items():
  File "/usr/local/lib/python2.7/dist-packages/cached_property.py", line 26, in __get__
    value = obj.__dict__[self.func.__name__] = self.func(obj)
  File "/usr/local/lib/python2.7/dist-packages/gixy/core/regexp.py", line 1004, in groups
    for name, parsed in extract_groups(self.parsed).items():
  File "/usr/local/lib/python2.7/dist-packages/gixy/core/regexp.py", line 1025, in parsed
    self._parsed = sre_parse.parse(FIX_NAMED_GROUPS_RE.sub('(?P<\\1>', self.source))
  File "/usr/local/lib/python2.7/dist-packages/gixy/core/sre_parse/sre_parse.py", line 707, in parse
    p = _parse_sub(source, pattern, 0)
  File "/usr/local/lib/python2.7/dist-packages/gixy/core/sre_parse/sre_parse.py", line 311, in _parse_sub
    itemsappend(_parse(source, state))
  File "/usr/local/lib/python2.7/dist-packages/gixy/core/sre_parse/sre_parse.py", line 666, in _parse
    p = _parse_sub(source, state)
  File "/usr/local/lib/python2.7/dist-packages/gixy/core/sre_parse/sre_parse.py", line 311, in _parse_sub
    itemsappend(_parse(source, state))
  File "/usr/local/lib/python2.7/dist-packages/gixy/core/sre_parse/sre_parse.py", line 688, in _parse
    code = _escape(source, this, state)
  File "/usr/local/lib/python2.7/dist-packages/gixy/core/sre_parse/sre_parse.py", line 301, in _escape
    raise error("bogus escape: %s" % repr(escape))
gixy.core.sre_parse.sre_constants.error: bogus escape: '\\x'

WileESpaghetti avatar May 11 '17 16:05 WileESpaghetti

Gixy v0.1.3 Python 2.7.13

WileESpaghetti avatar May 11 '17 16:05 WileESpaghetti

Hi! Thanks for your issue:) Gixy ignores empty directory or not existing files. The crashe happens by another reason, it can't parse one of your regular expression :( Did you uses \x in one of regex for if or location directives?

P.S. I'll make a normal error message in case of regex parsing error a bit later.

buglloc avatar May 11 '17 17:05 buglloc

Turns out someone accidentally turned \.xml into \xml in one of the redirect rules. Good catch by gixy, nginx -t didn't flinch at all!

WileESpaghetti avatar May 11 '17 17:05 WileESpaghetti