{"record":{"id":"eaa3005c00231694","repo":"OpenNHP/opennhp","slug":"path-is-not-a-regular-file","errorCode":null,"errorMessage":"path is not a regular file","messagePattern":"path is not a regular file","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"nhp/utils/crypto.go","lineNumber":131,"sourceCode":"\t\treturn \"\", \"\"\n\t}\n\tpivKey := x509.MarshalPKCS1PrivateKey(privateKey)\n\tpubKey := x509.MarshalPKCS1PublicKey(&privateKey.PublicKey)\n\n\treturn base64.StdEncoding.EncodeToString(pivKey), base64.StdEncoding.EncodeToString(pubKey)\n}\n\n// Md5sum computes MD5 checksum for file integrity verification (not cryptographic security)\n//\n//nolint:gosec // G401: MD5 used for file integrity checksums, not for cryptographic security\nfunc Md5sum(fullFilePath string) (string, error) {\n\tfileInfo, err := os.Stat(fullFilePath)\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"file not found: %w\", err)\n\t}\n\n\tif !fileInfo.Mode().IsRegular() {\n\t\treturn \"\", fmt.Errorf(\"path is not a regular file\")\n\t}\n\n\tfile, err := os.Open(fullFilePath) //nolint:gosec // G304: Path validated by os.Stat above\n\tif err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to open file: %w\", err)\n\t}\n\tdefer file.Close()\n\n\thasher := md5.New()\n\n\tif _, err := io.Copy(hasher, file); err != nil {\n\t\treturn \"\", fmt.Errorf(\"failed to read file content: %w\", err)\n\t}\n\n\t// Convert hash to hex string\n\treturn hex.EncodeToString(hasher.Sum(nil)), nil\n}\n","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/OpenNHP/opennhp/blob/6e04ca5ff03222a699c24205cd4bf8fee9af7ffe/nhp/utils/crypto.go#L113-L149","documentation":"After a successful os.Stat, Md5sum rejects paths that do not refer to a regular file (Mode().IsRegular() is false). Directories, device files, sockets, FIFOs and other special files are refused because hashing them is either meaningless (directories) or can block indefinitely (FIFOs/devices).","triggerScenarios":"Calling utils.Md5sum on a directory path, on /dev/null or another device node, on a named pipe, or on a unix socket instead of a regular file path.","commonSituations":"Config points the TA file setting at a directory (e.g. a plugins folder) instead of the .so file; a placeholder path like /dev/null was left in config; a symlink to a directory was passed.","solutions":["Confirm the target is a regular file: run stat -c '%F' <path> and expect 'regular file'","Correct the configured path to point to the actual file rather than a directory or special file","If you need to hash a directory's contents, hash the files inside it individually or hash an archive of it"],"exampleFix":"// before\nsum, err := utils.Md5sum(\"/opt/nhp/plugins\") // directory\n// after\nsum, err := utils.Md5sum(\"/opt/nhp/plugins/ta_plugin.so\")","handlingStrategy":"validation","validationCode":"if info, err := os.Stat(p); err != nil || !info.Mode().IsRegular() { return err }","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never point config at directories or device nodes"],"tags":["go","filesystem","md5","validation"],"backgroundTag":"path-is-not-a-regular-file","analyzedSha":"6e04ca5ff03222a699c24205cd4bf8fee9af7ffe","analyzedAt":"2026-09-07T15:44:59.941Z","contentChangedAt":"2026-09-07T15:44:59.941Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}