Commit 0bb4abaee2617204613bd5d88c90e1c407a50cc3

Stefan Sperling 2019-03-15T12:50:27

better fparseln error handling and memory leak fix in got_ref_list()

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
diff --git a/lib/reference.c b/lib/reference.c
index 07d58e1..739dc46 100644
--- a/lib/reference.c
+++ b/lib/reference.c
@@ -703,9 +703,14 @@ got_ref_list(struct got_reflist_head *refs, struct got_repository *repo)
 		const char delim[3] = {'\0', '\0', '\0'};
 		while (1) {
 			line = fparseln(f, &len, NULL, delim, 0);
-			if (line == NULL)
-				break;
+			if (line == NULL) {
+				if (feof(f))
+					break;
+				err = got_ferror(f, GOT_ERR_BAD_REF_DATA);
+				goto done;
+			}
 			err = parse_packed_ref_line(&ref, NULL, line);
+			free(line);
 			if (err)
 				goto done;
 			if (ref) {