[PATCH STABLE] bdiff: fix malloc(0) issue in fixws()

Jim Hague jim.hague at acm.org
Fri Feb 3 23:27:49 UTC 2012


# HG changeset patch
# User Jim Hague <jim.hague at acm.org>
# Date 1328311637 0
# Branch stable
# Node ID 6adf9f20da9889b65dd75265ab3ee223d666ae2c
# Parent  7e5a281a082cdbff4ae9553e01b5ff36dc2c11ee
bdiff: fix malloc(0) issue in fixws()

If fixws() is called on a zero-length string, malloc(0) is called and
expected to return a pointer. Which it does on e.g. Linux. AIX returns
NULL, which it is also legal, but the malloc() is then assumed to have
failed. So ensure a valid pointer is always returned.

diff -r 7e5a281a082c -r 6adf9f20da98 mercurial/bdiff.c
--- a/mercurial/bdiff.c	Fri Feb 03 19:47:09 2012 +0100
+++ b/mercurial/bdiff.c	Fri Feb 03 23:27:17 2012 +0000
@@ -443,7 +443,7 @@
 	r = PyBytes_AsString(s);
 	rlen = PyBytes_Size(s);
 
-	w = (char *)malloc(rlen);
+	w = (char *)malloc(rlen ? rlen : 1);
 	if (!w)
 		goto nomem;
 



More information about the Mercurial-devel mailing list