[PATCH] Avoid segfault when passed malformed refspec
From: Sean <hidden>
Date: 2016-06-15 22:44:09
Subsystem:
the rest · Maintainer:
Linus Torvalds
From: Sean <hidden>
Date: 2016-06-15 22:44:09
Subsystem:
the rest · Maintainer:
Linus Torvalds
A refspec typo can cause a Null-pointer dereference and segmentation fault. For instance, the space before the colon in the following example results in a segfault: $ git fetch ../repo refs/heads/* :refs/heads/* Segmentation fault (core dumped) To avoid the segfault, set an empty refspec destination string if one isn't found by parsing. Signed-off-by: Sean Estabrooks <redacted> --- remote.c | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-)
diff --git a/remote.c b/remote.c
index 0e00680..414c73a 100644
--- a/remote.c
+++ b/remote.c@@ -336,6 +336,8 @@ struct refspec *parse_ref_spec(int nr_refspec, const char **refspec) ep = gp; } rs[i].src = xstrndup(sp, ep - sp); + if (!rs[i].dst) + rs[i].dst = xstrdup(""); } return rs; }
--
1.5.4.rc5.20.g4b806