[PATCH stable] convert.cvs: Initialize state variable
Frank Kingswood
frank at kingswood-consulting.co.uk
Wed Mar 24 11:07:23 CDT 2010
Mads Kiilerich wrote:
> Ok. But I am -2 on having code paths where external input (no matter how
> unexpected and wrong) can cause use of uninitialized variables and crashes.
>
> Why should data be initialized when mode isn't?
>
> Initializing mode might not make the code correct, but it removes one
> problem.
>
> How about something like
>
> diff --git a/hgext/convert/cvs.py b/hgext/convert/cvs.py
> --- a/hgext/convert/cvs.py
> +++ b/hgext/convert/cvs.py
> @@ -226,7 +226,8 @@
> self.writep.write("Directory .\n%s\nco\n" % self.realroot)
> self.writep.flush()
>
> - data = ""
> + data = None
> + mode = ""
> while 1:
> line = self.readp.readline()
> if line.startswith("Created ") or line.startswith("Updated "):
> @@ -244,6 +245,8 @@
> data = chunkedread(self.readp, count)
> else:
> if line == "ok\n":
> + if data is None:
> + raise util.Abort(_('CVS response "ok" without
> data'))
> return (data, "x" in mode and "x" or "")
That creates a new problem in cases where we hit
data += line[1:]
(when data is None)
How about
--- a/hgext/convert/cvs.py Wed Mar 10 12:38:33 2010 +0100
+++ b/hgext/convert/cvs.py Wed Mar 24 16:06:43 2010 +0000
@@ -227,6 +227,7 @@
self.writep.flush()
data = ""
+ mode = None
while 1:
line = self.readp.readline()
if line.startswith("Created ") or line.startswith("Updated "):
@@ -244,6 +245,8 @@
data = chunkedread(self.readp, count)
else:
if line == "ok\n":
+ if mode is None:
+ raise util.Abort(_('malformed response from CVS'))
return (data, "x" in mode and "x" or "")
elif line.startswith("E "):
self.ui.warn(_("cvs server: %s\n") % line[2:])
More information about the Mercurial-devel
mailing list