dirstate: fix parse_dirstate() to error out if NULL entry created
authorYuya Nishihara <yuya@tcha.org>
Thu, 23 Sep 2021 16:44:17 +0900
changeset 48049 13efd8fdc55f
parent 48048 1b2ee68e85f9
child 48050 448aff4e8dd4
dirstate: fix parse_dirstate() to error out if NULL entry created Since 83f0e93ec34b "dirstate-item: move the C implementation to the same logic", dirstate_item_from_v1_data() gets more likely to return NULL, and the fuzzer crashes because of that.
mercurial/cext/parsers.c
--- a/mercurial/cext/parsers.c	Mon Sep 20 20:55:38 2021 +0200
+++ b/mercurial/cext/parsers.c	Thu Sep 23 16:44:17 2021 +0900
@@ -770,6 +770,8 @@
 
 		entry = (PyObject *)dirstate_item_from_v1_data(state, mode,
 		                                               size, mtime);
+		if (!entry)
+			goto quit;
 		cpos = memchr(cur, 0, flen);
 		if (cpos) {
 			fname = PyBytes_FromStringAndSize(cur, cpos - cur);