Use after free on rest api of branches
<!--- Please read this! Before opening a new issue, make sure to search for keywords in the issues filtered by the "regression" or "bug" label: - https://gitlab.com/gitlab-org/gitlab/issues?label_name%5B%5D=regression - https://gitlab.com/gitlab-org/gitlab/issues?label_name%5B%5D=bug and verify the issue you're about to submit isn't a duplicate. ---> ### Summary **We are testing Gitlab's rest apis and coming across some internal error. We will appreciate it if you developers could give us a hand and make a better community together. The error is explained as following:** **After deleting a branch, the deleted branch could still be referred in the following branch creation** It happens to me by API on the latest **Gitlab CE docker image RELEASE_VERSION=14.1.0-ce.0**. **RELATED ENDPOINTS:** - **POST /api/v4/projects/:id/repository/branches** - **DELETE /api/v4/projects/:id/repository/branches/:branch** - **GET /api/v4/projects/:id/repository/branches/:branch** - **POST /api/v4/projects/:id/repository/branches** <!-- Summarize the bug encountered concisely. --> ### Steps to reproduce **1. Create a branch on some project** `curl -X POST -H 'PRIVATE-TOKEN: <YOUR-TOKEN>' 'http://host/api/v4/projects/3/repository/branches?ref=master&branch=branchname1'` 201 Created It goes well and returns the new branch name <BRANCH_NAME> **2. Detele the branch** `curl -X DELETE -H 'PRIVATE-TOKEN: <YOUR-TOKEN>' 'http://host/api/v4/projects/3/repository/branches/<BRANCH_NAME>` It goes well and the server responds with 204 No Content **3. Get the branch** `curl -X GET -H 'PRIVATE-TOKEN: <YOUR-TOKEN>' 'http://host/api/v4/projects/3/repository/branches/<BRANCH_NAME>` It goes well and the server responds with 404 Branch not found **4. Create a new branch referring to deleted branch** `curl -X POST -H 'PRIVATE-TOKEN: <YOUR-TOKEN>' 'http://host/api/v4/projects/3/repository/branches?ref=<BRANCH_NAME>&branch=branchname2'` However, the server responds with 201 Created, managing to refer to a deleted branch. <!-- Describe how one can reproduce the issue - this is very important. Please use an ordered list. --> ### What is the current *bug* behavior? return "201 Created" <!-- Describe what actually happens. --> ### What is the expected *correct* behavior? return "404 Branch not found"
issue