Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: check-log panic with invalid memory address or nil pointer dereference #834

Merged
merged 1 commit into from
Apr 15, 2024

Conversation

ne-sachirou
Copy link
Member

I created the patch #823 , but this patch has a bug.

Procedure for reproducing :

  • Apply this patch.
    diff --git a/check-log/lib/check-log.go b/check-log/lib/check-log.go
    index f942c58..2efa68e 100644
    --- a/check-log/lib/check-log.go
    +++ b/check-log/lib/check-log.go
    @@ -16,6 +16,7 @@ import (
            "regexp"
            "strconv"
            "strings"
    +       "time"
    
            "github.com/jessevdk/go-flags"
            "github.com/mackerelio/checkers"
    @@ -566,6 +567,8 @@ var errFileNotFoundByInode = fmt.Errorf("old file not found")
    
     func findFileByInode(inode uint, dir string) (string, error) {
            entries, readDirErr := os.ReadDir(dir)
    +       fmt.Println("sleeping")
    +       time.Sleep(10 * time.Second)
            for _, entry := range entries {
                    fi, err := entry.Info()
                    if err != nil && !errors.Is(err, os.ErrNotExist) {
  • Create a log file. touch dummy.log
  • Create a state file. go run main.go -f ./dummy.log -p error -s $(pwd)
  • Rotate the log file. mv dummy.log dummy-1.log && touch dummy.log
  • Run check-log. go run main.go -f ./dummy.log -p error -s $(pwd)
  • When the "sleeping" is printed, remove the rotated log file. rm dummy-1.log
  • panic

@ne-sachirou ne-sachirou self-assigned this Apr 12, 2024
Copy link
Member

@Arthur1 Arthur1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@ne-sachirou ne-sachirou merged commit bfe4a9d into master Apr 15, 2024
16 checks passed
@ne-sachirou ne-sachirou deleted the fix-check-log-nil-ptr branch April 15, 2024 05:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants