Skip to content

Commit d109923

Browse files
authored
Make GetRepositoryByName more safer (#31712)
Fix #31708
1 parent 88decb6 commit d109923

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

models/repo/repo.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -745,17 +745,18 @@ func GetRepositoryByOwnerAndName(ctx context.Context, ownerName, repoName string
745745

746746
// GetRepositoryByName returns the repository by given name under user if exists.
747747
func GetRepositoryByName(ctx context.Context, ownerID int64, name string) (*Repository, error) {
748-
repo := &Repository{
749-
OwnerID: ownerID,
750-
LowerName: strings.ToLower(name),
751-
}
752-
has, err := db.GetEngine(ctx).Get(repo)
748+
var repo Repository
749+
has, err := db.GetEngine(ctx).
750+
Where("`owner_id`=?", ownerID).
751+
And("`lower_name`=?", strings.ToLower(name)).
752+
NoAutoCondition().
753+
Get(&repo)
753754
if err != nil {
754755
return nil, err
755756
} else if !has {
756757
return nil, ErrRepoNotExist{0, ownerID, "", name}
757758
}
758-
return repo, err
759+
return &repo, err
759760
}
760761

761762
// getRepositoryURLPathSegments returns segments (owner, reponame) extracted from a url

0 commit comments

Comments
 (0)