Commit 25dced9b436467b3d008cf5e63d7414cd6ea7239

Hiltjo Posthuma 2019-09-15T13:46:51

fix possible memleak in worklist_add() if path is too long

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
diff --git a/lib/worklist.c b/lib/worklist.c
index f765f02..bbdcd9d 100644
--- a/lib/worklist.c
+++ b/lib/worklist.c
@@ -51,8 +51,10 @@ worklist_add(const char *path, struct wklhead *worklist)
 		return got_error_from_errno("calloc");
 
 	len = strlcpy(wkl->wkl_path, path, sizeof(wkl->wkl_path));
-	if (len >= sizeof(wkl->wkl_path))
+	if (len >= sizeof(wkl->wkl_path)) {
+		free(wkl);
 		return got_error(GOT_ERR_NO_SPACE);
+	}
 
 	sigfillset(&new);
 	sigprocmask(SIG_BLOCK, &new, &old);