use go-homedir instead of standard os.userhomedir (#2262)

* use go-homedir instead of standard os.userhomedir

* set r.templatesConfig before write attempt to avoid panic
dev
Sajad 2022-07-13 13:33:13 +05:30 committed by GitHub
parent 04df7244d3
commit be73fde0db
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 7 additions and 6 deletions

View File

@ -3,11 +3,11 @@ package runner
import (
"fmt"
"net"
"os"
"path/filepath"
"runtime"
"strings"
"github.com/mitchellh/go-homedir"
"github.com/projectdiscovery/fileutil"
"github.com/projectdiscovery/goflags"
"github.com/projectdiscovery/nuclei/v2/pkg/catalog/config"
@ -29,7 +29,7 @@ func DoHealthCheck(options *types.Options) string {
var testResult string
nucleiIgnorePath := filepath.Join(cfgFileFolder, ".nuclei-ignore")
homedir, _ := os.UserHomeDir()
homedir, _ := homedir.Dir()
nucleiTemplatePath := filepath.Join(homedir, "nuclei-templates/.checksum")
for _, filename := range []string{cfgFilePath, nucleiIgnorePath, nucleiTemplatePath} {
ok, err := fileutil.IsReadable(filename)

View File

@ -73,10 +73,10 @@ func (r *Runner) updateTemplates() error { // TODO this method does more than ju
TemplatesDirectory: defaultTemplatesDirectory,
NucleiVersion: config.Version,
}
r.templatesConfig = currentConfig
if writeErr := config.WriteConfiguration(currentConfig); writeErr != nil {
return errors.Wrap(writeErr, "could not write template configuration")
}
r.templatesConfig = currentConfig
}
if r.options.TemplatesDirectory == "" {
if r.templatesConfig.TemplatesDirectory != "" {

View File

@ -5,6 +5,7 @@ import (
"path/filepath"
jsoniter "github.com/json-iterator/go"
"github.com/mitchellh/go-homedir"
"github.com/pkg/errors"
"gopkg.in/yaml.v2"
@ -41,7 +42,7 @@ func getConfigDetails() (string, error) {
// GetConfigDir returns the nuclei configuration directory
func GetConfigDir() (string, error) {
home, err := os.UserHomeDir()
home, err := homedir.Dir()
if err != nil {
return "", err
}

View File

@ -1,10 +1,10 @@
package utils
import (
"os"
"path/filepath"
"strings"
"github.com/mitchellh/go-homedir"
"github.com/projectdiscovery/nuclei/v2/pkg/catalog/config"
)
@ -35,7 +35,7 @@ func TemplatePathURL(fullPath string) (string, string) {
// GetDefaultTemplatePath on default settings
func GetDefaultTemplatePath() (string, error) {
home, err := os.UserHomeDir()
home, err := homedir.Dir()
if err != nil {
return "", err
}