Skip to content

Commit 4b709db

Browse files
committed
fix
1 parent c453210 commit 4b709db

File tree

17 files changed

+76
-53
lines changed

17 files changed

+76
-53
lines changed

models/repo/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -605,7 +605,7 @@ func (repo *Repository) IsGenerated() bool {
605605

606606
// RepoPath returns repository path by given user and repository name.
607607
func RepoPath(userName, repoName string) string { //revive:disable-line:exported
608-
return filepath.Join(user_model.UserPath(userName), strings.ToLower(repoName)+".git")
608+
return filepath.Join(setting.RepoRootPath, filepath.Clean(strings.ToLower(userName)), filepath.Clean(strings.ToLower(repoName)+".git"))
609609
}
610610

611611
// RepoPath returns the repository path

models/user/user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -980,7 +980,7 @@ func GetInactiveUsers(ctx context.Context, olderThan time.Duration) ([]*User, er
980980

981981
// UserPath returns the path absolute path of user repositories.
982982
func UserPath(userName string) string { //revive:disable-line:exported
983-
return filepath.Join(setting.RepoRootPath, strings.ToLower(userName))
983+
return filepath.Join(setting.RepoRootPath, filepath.Clean(strings.ToLower(userName)))
984984
}
985985

986986
// GetUserByID returns the user object by given ID if exists.

modules/auth/password/hash/argon2.go

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -61,17 +61,11 @@ func NewArgon2Hasher(config string) *Argon2Hasher {
6161
return nil
6262
}
6363

64-
parsed, err := parseUIntParam(vals[0], "time", "argon2", config, nil)
65-
hasher.time = uint32(parsed)
66-
67-
parsed, err = parseUIntParam(vals[1], "memory", "argon2", config, err)
68-
hasher.memory = uint32(parsed)
69-
70-
parsed, err = parseUIntParam(vals[2], "threads", "argon2", config, err)
71-
hasher.threads = uint8(parsed)
72-
73-
parsed, err = parseUIntParam(vals[3], "keyLen", "argon2", config, err)
74-
hasher.keyLen = uint32(parsed)
64+
var err error
65+
hasher.time, err = parseUintParam[uint32](vals[0], "time", "argon2", config, nil)
66+
hasher.memory, err = parseUintParam[uint32](vals[1], "memory", "argon2", config, err)
67+
hasher.threads, err = parseUintParam[uint8](vals[2], "threads", "argon2", config, err)
68+
hasher.keyLen, err = parseUintParam[uint32](vals[3], "keyLen", "argon2", config, err)
7569
if err != nil {
7670
return nil
7771
}

modules/auth/password/hash/common.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"strconv"
88

99
"code.gitea.io/gitea/modules/log"
10+
"code.gitea.io/gitea/modules/util"
1011
)
1112

1213
func parseIntParam(value, param, algorithmName, config string, previousErr error) (int, error) {
@@ -18,11 +19,12 @@ func parseIntParam(value, param, algorithmName, config string, previousErr error
1819
return parsed, previousErr // <- Keep the previous error as this function should still return an error once everything has been checked if any call failed
1920
}
2021

21-
func parseUIntParam(value, param, algorithmName, config string, previousErr error) (uint64, error) { //nolint:unparam // algorithmName is always argon2
22-
parsed, err := strconv.ParseUint(value, 10, 64)
22+
func parseUintParam[T uint32 | uint8](value, param, algorithmName, config string, previousErr error) (ret T, _ error) { //nolint:unparam // algorithmName is always argon2
23+
_, isUint32 := any(ret).(uint32)
24+
parsed, err := strconv.ParseUint(value, 10, util.Iif(isUint32, 32, 8))
2325
if err != nil {
2426
log.Error("invalid integer for %s representation in %s hash spec %s", param, algorithmName, config)
2527
return 0, err
2628
}
27-
return parsed, previousErr // <- Keep the previous error as this function should still return an error once everything has been checked if any call failed
29+
return T(parsed), previousErr // <- Keep the previous error as this function should still return an error once everything has been checked if any call failed
2830
}

modules/git/hook.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func GetHook(repoPath, name string) (*Hook, error) {
4545
}
4646
h := &Hook{
4747
name: name,
48-
path: filepath.Join(repoPath, "hooks", name+".d", name),
48+
path: filepath.Join(repoPath, filepath.Join("hooks", name+".d", name)),
4949
}
5050
isFile, err := util.IsFile(h.path)
5151
if err != nil {

modules/setting/config_env.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func decodeEnvSectionKey(encoded string) (ok bool, section, key string) {
6565
decodedBytes := make([]byte, len(toDecode)/2)
6666
for i := 0; i < len(toDecode)/2; i++ {
6767
// Can ignore error here as we know these should be hexadecimal from the regexp
68-
byteInt, _ := strconv.ParseInt(toDecode[2*i:2*i+2], 16, 0)
68+
byteInt, _ := strconv.ParseInt(toDecode[2*i:2*i+2], 16, 8)
6969
decodedBytes[i] = byte(byteInt)
7070
}
7171
if inKey {

modules/tempdir/tempdir.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ type TempDir struct {
1919
}
2020

2121
func (td *TempDir) JoinPath(elems ...string) string {
22-
return filepath.Join(append([]string{td.base, td.sub}, elems...)...)
22+
return filepath.Join(append([]string{td.base, td.sub}, filepath.Join(elems...))...)
2323
}
2424

2525
// MkdirAllSub works like os.MkdirAll, but the base directory must exist

modules/util/color.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func HexToRBGColor(colorString string) (float64, float64, float64) {
2626
if len(hexString) == 8 {
2727
hexString = hexString[0:6]
2828
}
29-
color, err := strconv.ParseUint(hexString, 16, 64)
29+
color, err := strconv.ParseUint(hexString, 16, 32)
3030
if err != nil {
3131
return 0, 0, 0
3232
}

routers/web/repo/activity.go

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,28 @@ func Activity(ctx *context.Context) {
2525

2626
ctx.Data["PageIsPulse"] = true
2727

28-
ctx.Data["Period"] = ctx.PathParam("period")
29-
3028
timeUntil := time.Now()
31-
var timeFrom time.Time
32-
33-
switch ctx.Data["Period"] {
29+
period, timeFrom := "weekly", timeUntil.Add(-time.Hour*168)
30+
switch ctx.PathParam("period") {
3431
case "daily":
35-
timeFrom = timeUntil.Add(-time.Hour * 24)
32+
period, timeFrom = "daily", timeUntil.Add(-time.Hour*24)
3633
case "halfweekly":
37-
timeFrom = timeUntil.Add(-time.Hour * 72)
34+
period, timeFrom = "halfweekly", timeUntil.Add(-time.Hour*72)
3835
case "weekly":
39-
timeFrom = timeUntil.Add(-time.Hour * 168)
36+
period, timeFrom = "weekly", timeUntil.Add(-time.Hour*168)
4037
case "monthly":
41-
timeFrom = timeUntil.AddDate(0, -1, 0)
38+
period, timeFrom = "monthly", timeUntil.AddDate(0, -1, 0)
4239
case "quarterly":
43-
timeFrom = timeUntil.AddDate(0, -3, 0)
40+
period, timeFrom = "quarterly", timeUntil.AddDate(0, -3, 0)
4441
case "semiyearly":
45-
timeFrom = timeUntil.AddDate(0, -6, 0)
42+
period, timeFrom = "semiyearly", timeUntil.AddDate(0, -6, 0)
4643
case "yearly":
47-
timeFrom = timeUntil.AddDate(-1, 0, 0)
48-
default:
49-
ctx.Data["Period"] = "weekly"
50-
timeFrom = timeUntil.Add(-time.Hour * 168)
44+
period, timeFrom = "yearly", timeUntil.AddDate(-1, 0, 0)
5145
}
5246
ctx.Data["DateFrom"] = timeFrom
5347
ctx.Data["DateUntil"] = timeUntil
54-
ctx.Data["PeriodText"] = ctx.Tr("repo.activity.period." + ctx.Data["Period"].(string))
48+
ctx.Data["Period"] = ctx.Data["Period"]
49+
ctx.Data["PeriodText"] = ctx.Tr("repo.activity.period." + period)
5550

5651
canReadCode := ctx.Repo.CanRead(unit.TypeCode)
5752
if canReadCode {

routers/web/repo/githttp.go

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ func (h *serviceHandler) sendFile(ctx *context.Context, contentType, file string
376376
ctx.Resp.WriteHeader(http.StatusBadRequest)
377377
return
378378
}
379-
reqFile := filepath.Join(h.getRepoDir(), file)
379+
reqFile := filepath.Join(h.getRepoDir(), filepath.Clean(file))
380380

381381
fi, err := os.Stat(reqFile)
382382
if os.IsNotExist(err) {
@@ -395,13 +395,12 @@ func (h *serviceHandler) sendFile(ctx *context.Context, contentType, file string
395395
var safeGitProtocolHeader = regexp.MustCompile(`^[0-9a-zA-Z]+=[0-9a-zA-Z]+(:[0-9a-zA-Z]+=[0-9a-zA-Z]+)*$`)
396396

397397
func prepareGitCmdWithAllowedService(service string) (*gitcmd.Command, error) {
398-
if service == "receive-pack" {
399-
return gitcmd.NewCommand("receive-pack"), nil
398+
if service == ServiceTypeReceivePack {
399+
return gitcmd.NewCommand(ServiceTypeReceivePack), nil
400400
}
401-
if service == "upload-pack" {
402-
return gitcmd.NewCommand("upload-pack"), nil
401+
if service == ServiceTypeUploadPack {
402+
return gitcmd.NewCommand(ServiceTypeUploadPack), nil
403403
}
404-
405404
return nil, fmt.Errorf("service %q is not allowed", service)
406405
}
407406

@@ -464,28 +463,35 @@ func serviceRPC(ctx *context.Context, h *serviceHandler, service string) {
464463
}
465464
}
466465

466+
const (
467+
ServiceTypeUploadPack = "upload-pack"
468+
ServiceTypeReceivePack = "receive-pack"
469+
)
470+
467471
// ServiceUploadPack implements Git Smart HTTP protocol
468472
func ServiceUploadPack(ctx *context.Context) {
469473
h := httpBase(ctx)
470474
if h != nil {
471-
serviceRPC(ctx, h, "upload-pack")
475+
serviceRPC(ctx, h, ServiceTypeUploadPack)
472476
}
473477
}
474478

475479
// ServiceReceivePack implements Git Smart HTTP protocol
476480
func ServiceReceivePack(ctx *context.Context) {
477481
h := httpBase(ctx)
478482
if h != nil {
479-
serviceRPC(ctx, h, "receive-pack")
483+
serviceRPC(ctx, h, ServiceTypeReceivePack)
480484
}
481485
}
482486

483487
func getServiceType(ctx *context.Context) string {
484-
serviceType := ctx.Req.FormValue("service")
485-
if !strings.HasPrefix(serviceType, "git-") {
486-
return ""
488+
switch ctx.Req.FormValue("service") {
489+
case "git-" + ServiceTypeUploadPack:
490+
return ServiceTypeUploadPack
491+
case "git-" + ServiceTypeReceivePack:
492+
return ServiceTypeReceivePack
487493
}
488-
return strings.TrimPrefix(serviceType, "git-")
494+
return ""
489495
}
490496

491497
func updateServerInfo(ctx gocontext.Context, dir string) []byte {

0 commit comments

Comments
 (0)