Commit 1bc5b05c614c7b10de021fa392943e8e6bd12c77

Patrick Steinhardt 2018-10-03T16:17:21

smart_pkt: do not accept callers passing in no line length Right now, we simply ignore the `linelen` parameter of `git_pkt_parse_line` in case the caller passed in zero. But in fact, we never want to assume anything about the provided buffer length and always want the caller to pass in the available number of bytes. And in fact, checking all the callers, one can see that the funciton is never being called in case where the buffer length is zero, and thus we are safe to remove this check.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
diff --git a/src/transports/smart_pkt.c b/src/transports/smart_pkt.c
index 4a5e71c..6a404ef 100644
--- a/src/transports/smart_pkt.c
+++ b/src/transports/smart_pkt.c
@@ -437,10 +437,10 @@ int git_pkt_parse_line(
 	}
 
 	/*
-	 * If we were given a buffer length, then make sure there is
-	 * enough in the buffer to satisfy this line
+	 * Make sure there is enough in the buffer to satisfy
+	 * this line.
 	 */
-	if (linelen > 0 && linelen < (size_t)len)
+	if (linelen < len)
 		return GIT_EBUFS;
 
 	/*