From 33c2c49627455bd19d411ecd858c2ca2eceab731 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Fri, 12 Mar 2021 01:54:18 +0100 Subject: [PATCH] Prevent panic when editing forked repos by API (#14960) (#14963) 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 Co-authored-by: zeripath --- routers/api/v1/repo/repo.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/routers/api/v1/repo/repo.go b/routers/api/v1/repo/repo.go index 116e413125..53ec0618ce 100644 --- a/routers/api/v1/repo/repo.go +++ b/routers/api/v1/repo/repo.go @@ -539,6 +539,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 }