commit a4435ef028e15d8a253cd768f608f9b852efd0ec from: Omar Polo via: Thomas Adam date: Wed Apr 05 20:24:26 2023 UTC gotd.conf: fix memleak in `protect' error path and disallow dups too ok stsp@ commit - 6d7eb4f7d125c942358a1f8edf1d350e74141112 commit + a4435ef028e15d8a253cd768f608f9b852efd0ec blob - d43ed3e568eed641142fe3b93aec55273e0b2876 blob + bc3deeee5a66ff48fabca32c4fa4a63f30d4ba4d --- gotd/parse.y +++ gotd/parse.y @@ -916,6 +916,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); @@ -926,9 +927,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; } @@ -953,6 +958,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) { @@ -973,10 +979,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; }