]> source.dussan.org Git - gitea.git/commitdiff
Prevent panic when editing forked repos by API (#14960)
authorzeripath <art27@cantab.net>
Thu, 11 Mar 2021 18:09:52 +0000 (18:09 +0000)
committerGitHub <noreply@github.com>
Thu, 11 Mar 2021 18:09:52 +0000 (19:09 +0100)
When editing forked repos using the API the BaseRepository needs to loaded
in order to check its visibility otherwise there will be NPE panic.

Fix #14956

Signed-off-by: Andrew Thornton <art27@cantab.net>
routers/api/v1/repo/repo.go

index b12797f83b990700b61e5e765c824be374a21c81..b7ed2951ad663c98333991d709893c65d2d5ca71 100644 (file)
@@ -556,6 +556,10 @@ func updateBasicProperties(ctx *context.APIContext, opts api.EditRepoOption) err
        if opts.Private != nil {
                // Visibility of forked repository is forced sync with base repository.
                if repo.IsFork {
+                       if err := repo.GetBaseRepo(); err != nil {
+                               ctx.Error(http.StatusInternalServerError, "Unable to load base repository", err)
+                               return err
+                       }
                        *opts.Private = repo.BaseRepo.IsPrivate
                }