WARNING - OLD ARCHIVES

This is an archived copy of the Xen.org mailing list, which we have preserved to ensure that existing links to archives are not broken. The live archive, which contains the latest emails, can be found at http://lists.xen.org/
   
 
 
Xen 
 
Home Products Support Community News
 
   
 

xen-devel

[Xen-devel] [PATCH] pygrub: fix IndexError when editing grub lines

To: xen-devel@xxxxxxxxxxxxxxxxxxx
Subject: [Xen-devel] [PATCH] pygrub: fix IndexError when editing grub lines
From: Ryan Harper <ryanh@xxxxxxxxxx>
Date: Tue, 7 Nov 2006 14:30:58 -0600
Delivery-date: Tue, 07 Nov 2006 12:31:26 -0800
Envelope-to: www-data@xxxxxxxxxxxxxxxxxx
List-help: <mailto:xen-devel-request@lists.xensource.com?subject=help>
List-id: Xen developer discussion <xen-devel.lists.xensource.com>
List-post: <mailto:xen-devel@lists.xensource.com>
List-subscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=subscribe>
List-unsubscribe: <http://lists.xensource.com/cgi-bin/mailman/listinfo/xen-devel>, <mailto:xen-devel-request@lists.xensource.com?subject=unsubscribe>
Sender: xen-devel-bounces@xxxxxxxxxxxxxxxxxxx
User-agent: Mutt/1.5.6+20040907i
pygrub will attempt to pop out-of-range values from a list if one sets
the cursor past the end of the last character and hits backspace while
in edit mode.

The attached patch fixes the stack trace below by not allowing the
cursor to move beyond the end of the line and also checks that the
current position is within the range of the line before popping.

Please apply.

Traceback (most recent call last):
  File "/usr/bin/pygrub", line 491, in ?
    curses.wrapper(run_main)
  File "/usr/lib64/python2.4/curses/wrapper.py", line 44, in wrapper
    return func(stdscr, *args, **kwds)
  File "/usr/bin/pygrub", line 447, in run_main
    sel = g.run()
  File "/usr/bin/pygrub", line 353, in run
    self.run_main(timeout)
  File "/usr/bin/pygrub", line 405, in run_main
    self.edit_entry(img)
  File "/usr/bin/pygrub", line 234, in edit_entry
    l = self.edit_line(img.lines[curline])
  File "/usr/bin/pygrub", line 266, in edit_line
    ret = t.edit()
  File "/usr/bin/pygrub", line 135, in edit
    r = curses.textpad.Textbox.edit(self)
  File "/usr/lib64/python2.4/curses/textpad.py", line 157, in edit
    if not self.do_command(ch):
  File "/usr/bin/pygrub", line 120, in do_command
    self.line.pop(self.pos)
IndexError: pop index out of range

-- 
Ryan Harper
Software Engineer; Linux Technology Center
IBM Corp., Austin, Tx
(512) 838-9253   T/L: 678-9253
ryanh@xxxxxxxxxx


diffstat output:
 pygrub |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

Signed-off-by: Ryan Harper <ryanh@xxxxxxxxxx>
---
diff -r 5a41ea282c86 tools/pygrub/src/pygrub
--- a/tools/pygrub/src/pygrub   Tue Nov 07 11:54:52 2006 +0000
+++ b/tools/pygrub/src/pygrub   Tue Nov 07 14:20:11 2006 -0600
@@ -117,13 +117,17 @@ class GrubLineEditor(curses.textpad.Text
         elif ch in (curses.ascii.BS,curses.KEY_BACKSPACE):
             if self.pos > 0:
                 self.pos -= 1
-                self.line.pop(self.pos)
+                # only pop char if pos is within line
+                if self.pos <= len(self.line):
+                    self.line.pop(self.pos)
         elif ch == curses.ascii.EOT:                           # ^d
             self.line.pop(self.pos)
         elif ch == curses.ascii.ENQ:                           # ^e
             self.pos = len(self.line)
         elif ch in (curses.ascii.ACK, curses.KEY_RIGHT):
-            self.pos +=1
+            # only allow cursor to move to end of the line
+            if self.pos+1 <= len(self.line):
+                self.pos +=1
         elif ch == curses.ascii.VT:                            # ^k
             self.line = self.line[:self.pos]
         else:

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel

<Prev in Thread] Current Thread [Next in Thread>