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

read kernel config from /boot #271

Merged
merged 1 commit into from
Dec 19, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions cmd/kernel.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package cmd

import (
"github.com/slimm609/checksec/pkg/utils"
"fmt"
"os"
"strings"

"github.com/slimm609/checksec/pkg/utils"
"github.com/spf13/cobra"
)

Expand All @@ -14,8 +17,27 @@ var kernelCmd = &cobra.Command{
var configFile string
if len(args) > 0 {
configFile = args[0]
} else {
} else if _, err := os.Stat("/proc/config.gz"); err == nil {
configFile = "/proc/config.gz"
} else {
osReleaseFile := "/proc/sys/kernel/osrelease"
_, err := os.Stat(osReleaseFile)
if err != nil {
fmt.Println("Error: could not find kernel config")
os.Exit(1)
}
osReleaseVersion, err := os.ReadFile(osReleaseFile)
if err != nil {
fmt.Println("Error: could not find kernel config")
os.Exit(1)
}
content := strings.ReplaceAll(string(osReleaseVersion), "\n", "")
configFile = fmt.Sprintf("%s-%s", "/boot/config", content)
_, err = os.Stat(configFile)
if err != nil {
fmt.Println("Error: could not find kernel config")
os.Exit(1)
}
}

utils.CheckFileExists(configFile)
Expand Down
Loading