"netrc" hack to strip comments before processing.

Processing comments seems to trigger a bug on (some?) Windows systems
due to a negative seek. This CL runs a comment-free version of the
"netrc" file through the parser.

BUG=chromium:664664
TEST=local
  - Uploaded this CL with the change.

Change-Id: I65f5d2f8c1162b3b3a13c66d8becb1cfccf27991
Reviewed-on: https://chromium-review.googlesource.com/411455
Reviewed-by: Nodir Turakulov <nodir@chromium.org>
Reviewed-by: Michael Moss <mmoss@chromium.org>
Commit-Queue: Daniel Jacques <dnj@chromium.org>
changes/55/411455/3
Dan Jacques 9 years ago committed by Commit Bot
parent 1a60c9c786
commit 1d949fd373

@ -34,6 +34,22 @@ TRY_LIMIT = 5
GERRIT_PROTOCOL = 'https'
# Processing comments in "netrc" can trigger a bug in Windows.
# See crbug.com/664664
class safeNetrc(netrc.netrc):
# pylint: disable=redefined-builtin
def __init__(self, file=None):
self._orig_parse, self._parse = self._parse, self._safe_parse
netrc.netrc.__init__(self, file=file)
# pylint: disable=redefined-builtin
def _safe_parse(self, file, fp, default_netrc):
# Buffer the file.
sio = StringIO(''.join(l for l in fp
if l.strip() and not l.strip().startswith('#')))
return self._orig_parse(file, sio, default_netrc)
class GerritError(Exception):
"""Exception class for errors commuicating with the gerrit-on-borg service."""
def __init__(self, http_status, *args, **kwargs):
@ -115,13 +131,13 @@ class CookiesAuthenticator(Authenticator):
def _get_netrc(cls):
path = cls.get_netrc_path()
if not os.path.exists(path):
return netrc.netrc(os.devnull)
return safeNetrc(os.devnull)
try:
return netrc.netrc(path)
return safeNetrc(path)
except IOError:
print >> sys.stderr, 'WARNING: Could not read netrc file %s' % path
return netrc.netrc(os.devnull)
return safeNetrc(os.devnull)
except netrc.NetrcParseError:
st = os.stat(path)
if st.st_mode & (stat.S_IRWXG | stat.S_IRWXO):
@ -133,7 +149,7 @@ class CookiesAuthenticator(Authenticator):
print >> sys.stderr, ('ERROR: Cannot use netrc file %s due to a '
'parsing error.' % path)
raise
return netrc.netrc(os.devnull)
return safeNetrc(os.devnull)
@classmethod
def get_gitcookies_path(cls):

Loading…
Cancel
Save