commit:     1375a55bd6f9a35ee1a4b4ec78b84f830cfb41a9
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon May  4 05:55:20 2015 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon May  4 06:41:58 2015 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=1375a55b

varexpand: fix IndexError (bug 548556)

This handles two cases where varexpand incremented the index without
checking bounds.

X-Gentoo-Bug: 548556
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=548556
X-Gentoo-forum-thread: https://forums.gentoo.org/viewtopic-t-1016432.html
Acked-by: Brian Dolbec <dolsen <AT> gentoo.org>

 pym/portage/util/__init__.py | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/pym/portage/util/__init__.py b/pym/portage/util/__init__.py
index 48cd1b7..c0b509b 100644
--- a/pym/portage/util/__init__.py
+++ b/pym/portage/util/__init__.py
@@ -850,8 +850,20 @@ def varexpand(mystring, mydict=None, error_leader=None):
                                        continue
                        elif current == "$":
                                pos += 1
+                               if pos == length:
+                                       # shells handle this like \$
+                                       newstring.append(current)
+                                       continue
+
                                if mystring[pos] == "{":
                                        pos += 1
+                                       if pos == length:
+                                               msg = 
_varexpand_unexpected_eof_msg
+                                               if error_leader is not None:
+                                                       msg = error_leader() + 
msg
+                                               writemsg(msg + "\n", 
noiselevel=-1)
+                                               return ""
+
                                        braced = True
                                else:
                                        braced = False

Reply via email to