Skip to content

cgitb failures #41022

Closed
Closed

Description

@rgbecker
mannequin
BPO 1047397
Nosy @devdanzin, @ethanfurman, @iritkatriel
PRs
  • bpo-1047397: prevent repr/getattr exceptions in cgitb #15094
  • Files
  • cgitbbug.py: Trivial exciter for the problems
  • bugfix000.patch: Patch against 2.4a3 to fix 1047397
  • terror.py: erroring value and usage
  • bugfix001.patch: bugfix000.patch forgot in a message
  • bugfix002.patch: -4 lines, but more complex patch same end
  • bugfix003.patch: patch against cgitb.py in 3.4.1
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2022-03-13.17:34:55.090>
    created_at = <Date 2004-10-14.22:23:50.000>
    labels = ['easy', 'type-bug', 'library']
    title = 'cgitb failures'
    updated_at = <Date 2022-03-13.17:34:55.089>
    user = 'https://bugs.python.org/rgbecker'

    bugs.python.org fields:

    activity = <Date 2022-03-13.17:34:55.089>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = True
    closed_date = <Date 2022-03-13.17:34:55.090>
    closer = 'iritkatriel'
    components = ['Library (Lib)']
    creation = <Date 2004-10-14.22:23:50.000>
    creator = 'rgbecker'
    dependencies = []
    files = ['1427', '1428', '1429', '1430', '1431', '35995']
    hgrepos = []
    issue_num = 1047397
    keywords = ['patch', 'easy']
    message_count = 8.0
    messages = ['22695', '22696', '22697', '82098', '114382', '223448', '223464', '415057']
    nosy_count = 6.0
    nosy_names = ['jhylton', 'rgbecker', 'ajaksu2', 'ethan.furman', 'wam', 'iritkatriel']
    pr_nums = ['15094']
    priority = 'normal'
    resolution = 'wont fix'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue1047397'
    versions = ['Python 2.7', 'Python 3.4', 'Python 3.5']

    Activity

    1. rgbecker commented on Oct 14, 2004

      rgbeckermannequin
      MannequinAuthor

      cgitb fails when evaluating various reprs/getattrs. The bug
      demonstrator is cgitbbug.py. Below is the run output
      for two bugs. Fixes are possible by putting try: except
      around various evaluations. Although the test is
      artificial we found these could happen in real code.

      This is with 2.4a3 Windows XP

      Sample output

      C:\Python24>.\python \tmp\cgitbbug.py repr1
      2.4a3 (#56, Sep  2 2004, 20:50:21) [MSC v.1310 32 bit
      (Intel)]
      Traceback (most recent call last):
        File "\tmp\cgitbbug.py", line 36, in ?
          print cgitb.html(sys.exc_info(),context=3)
        File "C:\python24\lib\cgitb.py", line 155, in html
          dump.append('%s = %s' % (name,
      pydoc.html.repr(value)))
        File "C:\python24\lib\pydoc.py", line 352, in repr
          return Repr.repr(self, object)
        File "C:\python24\lib\repr.py", line 24, in repr
          return self.repr1(x, self.maxlevel)
        File "C:\python24\lib\pydoc.py", line 359, in repr1
          return self.escape(cram(stripid(repr(x)),
      self.maxother))
        File "\tmp\cgitbbug.py", line 12, in __repr__
          if self._mad=='repr1': raise ValueError('repr1
      madness')
      ValueError: repr1 madness
      
      C:\Python24>.\python \tmp\cgitbbug.py getattr1
      2.4a3 (#56, Sep  2 2004, 20:50:21) [MSC v.1310 32 bit
      (Intel)]
      Traceback (most recent call last):
        File "\tmp\cgitbbug.py", line 36, in ?
          print cgitb.html(sys.exc_info(),context=3)
        File "C:\python24\lib\cgitb.py", line 129, in html
          vars = scanvars(reader, frame, locals)
        File "C:\python24\lib\cgitb.py", line 83, in scanvars
          value = getattr(parent, token, __UNDEF__)
        File "\tmp\cgitbbug.py", line 16, in __getattr__
          if self._mad=='getattr1': raise
      ValueError('getattr1 madness')
      ValueError: getattr1 madness

      C:\Python24>

    2. added
      stdlib
      on Oct 14, 2004
    3. rgbecker commented on Oct 14, 2004

      rgbeckermannequin
      MannequinAuthor

      Logged In: YES
      user_id=6946

      Bug fix added

    4. jhylton commented on Nov 7, 2004

      jhyltonmannequin
      Mannequin

      Logged In: YES
      user_id=31392

      The formatting of this patch is wrong. There is a long line
      (>80 chars) and missing whitespace around commas, operators,
      etc.

    5. devdanzin commented on Feb 14, 2009

      devdanzinmannequin
      Mannequin

      Confirmed on trunk.

    6. added
      type-bug
      on Feb 14, 2009
    7. BreamoreBoy commented on Aug 19, 2010

      BreamoreBoymannequin
      Mannequin

      Anyone interested in running with this as it's still a problem in all versions?

    8. BreamoreBoy commented on Jul 18, 2014

      BreamoreBoymannequin
      Mannequin

      The output now is

      c:\Users\Mark\PythonIssues>cgitbbug.py getattr1
      3.4.1 (v3.4.1:c0e311e010fc, May 18 2014, 10:38:22) [MSC v.1600 32 bit (Intel)]
      Traceback (most recent call last):
        File "C:\Users\Mark\PythonIssues\cgitbbug.py", line 34, in <module>
          d.h('aaa')
        File "C:\Users\Mark\PythonIssues\cgitbbug.py", line 23, in _f
          raiseError()
        File "C:\Users\Mark\PythonIssues\cgitbbug.py", line 3, in raiseError
          raise ValueError('original error')
      ValueError: original error
      
      During handling of the above exception, another exception occurred:
      
      Traceback (most recent call last):
        File "C:\Users\Mark\PythonIssues\cgitbbug.py", line 36, in <module>
          print(cgitb.html(sys.exc_info(),context=3))
        File "c:\python34\lib\cgitb.py", line 136, in html
          vars = scanvars(reader, frame, locals)
        File "c:\python34\lib\cgitb.py", line 88, in scanvars
          value = getattr(parent, token, __UNDEF__)
        File "C:\Users\Mark\PythonIssues\cgitbbug.py", line 16, in __getattr__
          if self._mad=='getattr1': raise ValueError('getattr1 madness')
      ValueError: getattr1 madness

      Thus the madness has been fixed and this can be closed as "out of date".

    9. rgbecker commented on Jul 19, 2014

      rgbeckermannequin
      MannequinAuthor

      I'll repeat the post I made to BreamoreBoy regarding this bug:

      "re: http://bugs.python.org/issue1047397

      this bug is now 10 years old. I'm not sure why it's to be considered
      closed because the original intent of the bug report was that the html
      output of the cgitb module could be confused and errors during
      evaluation could make the html output fail. So far as I can tell by
      modifying the original cgitbbug.py to run under python 3.4.1 it still
      fails to correctly produce html when a bug occurs in cgitb.html.
      Producing a more reasonable traceback is certainly a step forward, but
      I think that has been true since at least 3.1. The whole point of
      cgitb is to produce something reasonable for an html consumer."

      I have re-created the original 002 patch with mods for python 3.4.1. It's a bit of a shame that this wasn't fixed 10 years ago. Hopefully any style pedants will find this patch more acceptable. Personally I don't think style errors should prevent a working fix from being adopted. I would have just fixed the fix style and carped afterwards.

    10. iritkatriel commented on Mar 13, 2022

      @iritkatriel
      Member

      cgi/cgitb are deprecated as per PEP-594, so there won't be further enhancements to them.

    11. transferred this issue fromon Apr 9, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      easystdlibtype-bug

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions