commit f0426190497546f380f3bbd5d7cf464e5423a1c6 from: Omar Polo date: Wed Apr 05 07:55:50 2023 UTC gotd.conf: fix memleak in `protect' error path and disallow dups too ok stsp@ commit - 9afa3de221045d529287cc3fa75fdc2915aed5c1 commit + f0426190497546f380f3bbd5d7cf464e5423a1c6 blob - 3b6daa1a2a93121b0ee884ddd8cd1ceb5e85fa9b blob + 44801b6de7df40ed4df2acd8f523a9ccabe7170b --- gotd/parse.y +++ gotd/parse.y @@ -918,6 +918,7 @@ static int conf_protect_ref_namespace(struct got_pathlist_head *refs, char *namespace) { const struct got_error *error; + struct got_pathlist_entry *new; char *s; got_path_strip_trailing_slashes(namespace); @@ -928,9 +929,13 @@ conf_protect_ref_namespace(struct got_pathlist_head *r return -1; } - error = got_pathlist_insert(NULL, refs, s, NULL); - if (error) { - yyerror("got_pathlist_insert: %s", error->msg); + error = got_pathlist_insert(&new, refs, s, NULL); + if (error || new == NULL) { + free(s); + if (error) + yyerror("got_pathlist_insert: %s", error->msg); + else + yyerror("duplicate protect namespace %s", namespace); return -1; } @@ -955,6 +960,7 @@ static int conf_protect_branch(struct gotd_repo *repo, char *branchname) { const struct got_error *error; + struct got_pathlist_entry *new; char *refname; if (strncmp(branchname, "refs/heads/", 11) != 0) { @@ -975,10 +981,14 @@ conf_protect_branch(struct gotd_repo *repo, char *bran return -1; } - error = got_pathlist_insert(NULL, &repo->protected_branches, + error = got_pathlist_insert(&new, &repo->protected_branches, refname, NULL); - if (error) { - yyerror("got_pathlist_insert: %s", error->msg); + if (error || new == NULL) { + free(refname); + if (error) + yyerror("got_pathlist_insert: %s", error->msg); + else + yyerror("duplicate protect branch %s", branchname); return -1; }