Skip to content

-o NUL fails on Windows: CreateFile opens devices with O_TRUNC #208

Closed

Description

@TMHSDigital

Summary

On Windows, -o NUL (and -stats NUL, -sarif NUL) fails with open NUL: Incorrect function. and exit 1, while -o /dev/null works on Linux and macOS. The results-file code opens non-regular targets with O_TRUNC, which the Windows NUL device rejects.

Where

  • internal/output/file.go:39 (CreateFile, non-regular branch)

Details

CreateFile writes a device or pipe target directly:

if !fi.Mode().IsRegular() {
	f, err := os.OpenFile(path, os.O_WRONLY|os.O_TRUNC, 0)

os.Stat("NUL") reports a non-regular file on Windows, but opening it with O_TRUNC returns ERROR_INVALID_FUNCTION.

Impact

Windows users can't discard results with -o NUL, for example to keep only -stats or -sarif. Low severity: a workaround is to omit -o.

Steps to reproduce

  1. On Windows: subenum -simulate -w examples/sample_wordlist.txt -o NUL example.com
  2. Output: Error: creating output file: open NUL: Incorrect function. and exit code 1.

Suggested fix

Drop O_TRUNC for non-regular targets (truncating a device or pipe is meaningless), or retry without it when it fails. Then remove the Windows skip in TestCreateFileWritesNonRegularTargetDirectly (internal/output/lifecycle_test.go).

Acceptance criteria

  • -o NUL works on Windows
  • TestCreateFileWritesNonRegularTargetDirectly runs on Windows (CI's test-os job covers it)

Getting started

  • Relevant files: internal/output/file.go, internal/output/lifecycle_test.go
  • How to run tests: go test ./internal/output/

Related: #171


Filed by repo-audit/fix-issues at 28de702. Severity: low. Effort: S. audit-key: bug|internal/output/file.go|CreateFile

Activity

  1. added
    bug
    good first issue
    area: output
    severity: low
    on Nov 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: outputbuggood first issueseverity: low

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions