Fix CodeQL code scanning alerts (#36858)
Fixes 10 CodeQL code scanning alerts: - Change `NewPagination`/`SetLinkHeader` to accept `int64` for total count, clamping internally to fix incorrect-integer-conversion alerts ([#110](https://github.com/go-gitea/gitea/security/code-scanning/110), [#114](https://github.com/go-gitea/gitea/security/code-scanning/114), [#115](https://github.com/go-gitea/gitea/security/code-scanning/115), [#116](https://github.com/go-gitea/gitea/security/code-scanning/116)) - Use `strconv.Atoi()` in `htmlrenderer.go` to avoid int64 intermediate ([#105](https://github.com/go-gitea/gitea/security/code-scanning/105), [#106](https://github.com/go-gitea/gitea/security/code-scanning/106)) - Clamp regex match indices in `escape_stream.go` to fix allocation-size-overflow ([#161](https://github.com/go-gitea/gitea/security/code-scanning/161), [#162](https://github.com/go-gitea/gitea/security/code-scanning/162), [#163](https://github.com/go-gitea/gitea/security/code-scanning/163)) - Cap slice pre-allocation in `GetIssueDependencies` ([#181](https://github.com/go-gitea/gitea/security/code-scanning/181)) --------- Co-authored-by: Claude (Opus 4.6) <noreply@anthropic.com> Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
This commit is contained in:
@@ -59,7 +59,7 @@ func CodeSearch(ctx *context.Context) {
|
||||
}
|
||||
|
||||
var (
|
||||
total int
|
||||
total int64
|
||||
searchResults []*code_indexer.Result
|
||||
searchResultLanguages []*code_indexer.SearchResultLanguages
|
||||
)
|
||||
|
||||
@@ -301,15 +301,15 @@ func Milestones(ctx *context.Context) {
|
||||
return !showRepoIDs.Contains(v)
|
||||
})
|
||||
|
||||
var pagerCount int
|
||||
var pagerCount int64
|
||||
if isShowClosed {
|
||||
ctx.Data["State"] = "closed"
|
||||
ctx.Data["Total"] = totalMilestoneStats.ClosedCount
|
||||
pagerCount = int(milestoneStats.ClosedCount)
|
||||
pagerCount = milestoneStats.ClosedCount
|
||||
} else {
|
||||
ctx.Data["State"] = "open"
|
||||
ctx.Data["Total"] = totalMilestoneStats.OpenCount
|
||||
pagerCount = int(milestoneStats.OpenCount)
|
||||
pagerCount = milestoneStats.OpenCount
|
||||
}
|
||||
|
||||
ctx.Data["Milestones"] = milestones
|
||||
@@ -578,11 +578,11 @@ func buildIssueOverview(ctx *context.Context, unitType unit.Type) {
|
||||
}
|
||||
|
||||
// Will be posted to ctx.Data.
|
||||
var shownIssues int
|
||||
var shownIssues int64
|
||||
if !isShowClosed {
|
||||
shownIssues = int(issueStats.OpenCount)
|
||||
shownIssues = issueStats.OpenCount
|
||||
} else {
|
||||
shownIssues = int(issueStats.ClosedCount)
|
||||
shownIssues = issueStats.ClosedCount
|
||||
}
|
||||
|
||||
ctx.Data["IsShowClosed"] = isShowClosed
|
||||
|
||||
@@ -61,11 +61,11 @@ func prepareUserNotificationsData(ctx *context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
pager := context.NewPagination(int(total), perPage, page, 5)
|
||||
pager := context.NewPagination(total, perPage, page, 5)
|
||||
if pager.Paginater.Current() < page {
|
||||
// use the last page if the requested page is more than total pages
|
||||
page = pager.Paginater.Current()
|
||||
pager = context.NewPagination(int(total), perPage, page, 5)
|
||||
pager = context.NewPagination(total, perPage, page, 5)
|
||||
}
|
||||
|
||||
statuses := []activities_model.NotificationStatus{queryStatus, activities_model.NotificationStatusPinned}
|
||||
@@ -286,7 +286,7 @@ func NotificationSubscriptions(ctx *context.Context) {
|
||||
ctx.Data["Title"] = ctx.Tr("notification.subscriptions")
|
||||
|
||||
// redirect to last page if request page is more than total pages
|
||||
pager := context.NewPagination(int(count), setting.UI.IssuePagingNum, page, 5)
|
||||
pager := context.NewPagination(count, setting.UI.IssuePagingNum, page, 5)
|
||||
if pager.Paginater.Current() < page {
|
||||
ctx.Redirect(fmt.Sprintf("/notifications/subscriptions?page=%d", pager.Paginater.Current()))
|
||||
return
|
||||
@@ -370,12 +370,11 @@ func NotificationWatching(ctx *context.Context) {
|
||||
ctx.ServerError("SearchRepository", err)
|
||||
return
|
||||
}
|
||||
total := int(count)
|
||||
ctx.Data["Total"] = total
|
||||
ctx.Data["Total"] = count
|
||||
ctx.Data["Repos"] = repos
|
||||
|
||||
// redirect to last page if request page is more than total pages
|
||||
pager := context.NewPagination(total, setting.UI.User.RepoPagingNum, page, 5)
|
||||
pager := context.NewPagination(count, setting.UI.User.RepoPagingNum, page, 5)
|
||||
pager.AddParamFromRequest(ctx.Req)
|
||||
ctx.Data["Page"] = pager
|
||||
|
||||
|
||||
@@ -127,7 +127,7 @@ func ListPackages(ctx *context.Context) {
|
||||
ctx.Data["IsOrganizationOwner"] = false
|
||||
}
|
||||
}
|
||||
pager := context.NewPagination(int(total), setting.UI.PackagesPagingNum, page, 5)
|
||||
pager := context.NewPagination(total, setting.UI.PackagesPagingNum, page, 5)
|
||||
pager.AddParamFromRequest(ctx.Req)
|
||||
ctx.Data["Page"] = pager
|
||||
ctx.HTML(http.StatusOK, tplPackagesList)
|
||||
@@ -412,7 +412,7 @@ func ListPackageVersions(ctx *context.Context) {
|
||||
|
||||
ctx.Data["Total"] = total
|
||||
|
||||
pager := context.NewPagination(int(total), setting.UI.PackagesPagingNum, page, 5)
|
||||
pager := context.NewPagination(total, setting.UI.PackagesPagingNum, page, 5)
|
||||
pager.AddParamFromRequest(ctx.Req)
|
||||
ctx.Data["Page"] = pager
|
||||
|
||||
|
||||
@@ -102,7 +102,7 @@ func prepareUserProfileTabData(ctx *context.Context, profileDbRepo *repo_model.R
|
||||
var (
|
||||
repos []*repo_model.Repository
|
||||
count int64
|
||||
total int
|
||||
total int64
|
||||
curRows int
|
||||
orderBy db.SearchOrderBy
|
||||
)
|
||||
@@ -157,10 +157,10 @@ func prepareUserProfileTabData(ctx *context.Context, profileDbRepo *repo_model.R
|
||||
switch tab {
|
||||
case "followers":
|
||||
ctx.Data["Cards"] = followers
|
||||
total = int(numFollowers)
|
||||
total = numFollowers
|
||||
case "following":
|
||||
ctx.Data["Cards"] = following
|
||||
total = int(numFollowing)
|
||||
total = numFollowing
|
||||
case "activity":
|
||||
if setting.Service.EnableUserHeatmap && activities_model.ActivityReadable(ctx.ContextUser, ctx.Doer) {
|
||||
ctx.Data["EnableHeatmap"] = true
|
||||
@@ -218,7 +218,7 @@ func prepareUserProfileTabData(ctx *context.Context, profileDbRepo *repo_model.R
|
||||
return
|
||||
}
|
||||
|
||||
total = int(count)
|
||||
total = count
|
||||
case "watching":
|
||||
repos, count, err = repo_model.SearchRepository(ctx, repo_model.SearchRepoOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
@@ -245,7 +245,7 @@ func prepareUserProfileTabData(ctx *context.Context, profileDbRepo *repo_model.R
|
||||
return
|
||||
}
|
||||
|
||||
total = int(count)
|
||||
total = count
|
||||
case "overview":
|
||||
if bytes, err := profileReadme.GetBlobContent(setting.UI.MaxDisplayFileSize); err != nil {
|
||||
log.Error("failed to GetBlobContent: %v", err)
|
||||
@@ -273,7 +273,7 @@ func prepareUserProfileTabData(ctx *context.Context, profileDbRepo *repo_model.R
|
||||
return
|
||||
}
|
||||
ctx.Data["Cards"] = orgs
|
||||
total = int(count)
|
||||
total = count
|
||||
default: // default to "repositories"
|
||||
repos, count, err = repo_model.SearchRepository(ctx, repo_model.SearchRepoOptions{
|
||||
ListOptions: db.ListOptions{
|
||||
@@ -300,7 +300,7 @@ func prepareUserProfileTabData(ctx *context.Context, profileDbRepo *repo_model.R
|
||||
return
|
||||
}
|
||||
|
||||
total = int(count)
|
||||
total = count
|
||||
}
|
||||
ctx.Data["Repos"] = repos
|
||||
ctx.Data["Total"] = total
|
||||
|
||||
@@ -222,7 +222,7 @@ func Organization(ctx *context.Context) {
|
||||
}
|
||||
|
||||
ctx.Data["Orgs"] = orgs
|
||||
pager := context.NewPagination(int(total), opts.PageSize, opts.Page, 5)
|
||||
pager := context.NewPagination(total, opts.PageSize, opts.Page, 5)
|
||||
pager.AddParamFromRequest(ctx.Req)
|
||||
ctx.Data["Page"] = pager
|
||||
ctx.HTML(http.StatusOK, tplSettingsOrganization)
|
||||
@@ -244,13 +244,13 @@ func Repos(ctx *context.Context) {
|
||||
if opts.Page <= 0 {
|
||||
opts.Page = 1
|
||||
}
|
||||
start := (opts.Page - 1) * opts.PageSize
|
||||
end := start + opts.PageSize
|
||||
start := int64((opts.Page - 1) * opts.PageSize)
|
||||
end := start + int64(opts.PageSize)
|
||||
|
||||
adoptOrDelete := ctx.IsUserSiteAdmin() || (setting.Repository.AllowAdoptionOfUnadoptedRepositories && setting.Repository.AllowDeleteOfUnadoptedRepositories)
|
||||
|
||||
ctxUser := ctx.Doer
|
||||
count := 0
|
||||
var count int64
|
||||
|
||||
if adoptOrDelete {
|
||||
repoNames := make([]string, 0, setting.UI.Admin.UserPagingNum)
|
||||
@@ -310,12 +310,12 @@ func Repos(ctx *context.Context) {
|
||||
ctx.Data["Dirs"] = repoNames
|
||||
ctx.Data["ReposMap"] = repos
|
||||
} else {
|
||||
repos, count64, err := repo_model.GetUserRepositories(ctx, repo_model.SearchRepoOptions{Actor: ctxUser, Private: true, ListOptions: opts})
|
||||
repos, reposCount, err := repo_model.GetUserRepositories(ctx, repo_model.SearchRepoOptions{Actor: ctxUser, Private: true, ListOptions: opts})
|
||||
if err != nil {
|
||||
ctx.ServerError("GetUserRepositories", err)
|
||||
return
|
||||
}
|
||||
count = int(count64)
|
||||
count = reposCount
|
||||
|
||||
for i := range repos {
|
||||
if repos[i].IsFork {
|
||||
|
||||
Reference in New Issue
Block a user