Skip to content

Commit b87c88b

Browse files
committed
fix code warnning
1 parent 128aa12 commit b87c88b

File tree

4 files changed

+27
-3
lines changed

4 files changed

+27
-3
lines changed

.github/workflows/codeql.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ on:
66
pull_request:
77
branches: [main, develop, release_*]
88

9+
# Add explicit permissions - restrict to only what's needed
10+
permissions:
11+
contents: read
12+
913
jobs:
1014
lint:
1115
runs-on: ubuntu-latest

.github/workflows/docker-s3-deploy.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ on:
1010
description: 'AWS region for the S3 bucket (e.g., ap-southeast-1)'
1111
required: true # Makes the input mandatory
1212

13+
# Add explicit permissions - restrict to only what's needed
14+
permissions:
15+
contents: read
16+
id-token: write # Needed for AWS credential provider
17+
1318
jobs:
1419
build-and-sign:
1520
runs-on: ubuntu-latest

tools/toolkit/src/main/java/org/tron/plugins/DbQuery.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -682,8 +682,8 @@ private long computeReward(long cycle, List<Pair<byte[], Long>> votes) {
682682
continue;
683683
}
684684
long userVote = vote.getValue();
685-
double voteRate = (double) userVote / totalVote;
686-
reward += voteRate * totalReward;
685+
// Replace floating-point division with integer-based calculation
686+
reward += (userVote * totalReward) / totalVote;
687687
}
688688
return reward;
689689
}

tools/trond/utils/http.go

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -445,8 +445,17 @@ func ExtractTgzWithStatus(tgzFile, destDir string) error {
445445
return fmt.Errorf("error reading tar: %v", err)
446446
}
447447

448+
sanitizedName := filepath.Clean(header.Name)
449+
if strings.Contains(sanitizedName, "..") || strings.HasPrefix(sanitizedName, "/") || strings.HasPrefix(sanitizedName, "../") {
450+
return fmt.Errorf("invalid file path in archive: %s", header.Name)
451+
}
452+
448453
// Target file path
449-
target := filepath.Join(destDir, header.Name)
454+
target := filepath.Join(destDir, sanitizedName)
455+
// Ensure the target path is still within the destination directory
456+
if !strings.HasPrefix(target, filepath.Clean(destDir)+string(os.PathSeparator)) {
457+
return fmt.Errorf("attempted directory traversal: %s", header.Name)
458+
}
450459

451460
switch header.Typeflag {
452461
case tar.TypeDir:
@@ -498,6 +507,12 @@ func ExtractTgzWithStatus(tgzFile, destDir string) error {
498507
case tar.TypeLink:
499508
// Create hard link
500509
linkTarget := filepath.Join(destDir, header.Linkname)
510+
// Sanitize the link target to prevent directory traversal
511+
sanitizedLinkTarget := filepath.Clean(linkTarget)
512+
if !strings.HasPrefix(sanitizedLinkTarget, filepath.Clean(destDir)+string(os.PathSeparator)) {
513+
return fmt.Errorf("attempted directory traversal in hard link: %s -> %s", header.Name, header.Linkname)
514+
}
515+
501516
if err := os.Link(linkTarget, target); err != nil {
502517
return fmt.Errorf("failed to create hard link: %v", err)
503518
}

0 commit comments

Comments
 (0)