Skip to content

Creating a new logger on Linux without write permissions to /var causes panic #1227

@timraymond

Description

@timraymond

When creating a new log.(*Logger) with NewLogger, and then subsequently initializing it with log.(*Logger).Init, a panic will result when any of the logging methods are invoked (e.g. log.(*Logger).Debugf). The resulting panic (abridged for privacy) is:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x18 pc=0x4feb76]

goroutine 1 [running]:
log.(*Logger).Output(0xc00051e7d0, 0x13, {0xc000524b70, 0x23})
        /home/tim/goroots/go1.17/src/log/log.go:184 +0x356
log.(*Logger).Printf(0x198e233, {0xc00055e198, 0xc000511ac8}, {0xc00022d9a0, 0x2, 0x73e3a5})
        /home/tim/goroots/go1.17/src/log/log.go:191 +0x4c
github.com/Azure/azure-container-networking/log.(*Logger).logf(0xc000213810, {0x19937f5, 0xb}, {0xc00022d9a0, 0x1, 0x1})
        /home/tim/go/pkg/mod/github.com/!azure/azure-container-networking@v1.4.16/log/logger.go:204 +0xf0
github.com/Azure/azure-container-networking/log.(*Logger).Logf(0xc000213810, {0x19937f5, 0x7fa856e433a0}, {0xc00022d9a0, 0x10, 0x7fa87dc72a68})
        /home/tim/go/pkg/mod/github.com/!azure/azure-container-networking@v1.4.16/log/logger.go:210 +0x8c
github.com/Azure/azure-container-networking/log.(*Logger).Debugf(...)
        /home/tim/go/pkg/mod/github.com/!azure/azure-container-networking@v1.4.16/log/logger.go:229

The root cause of this is the nil writer being provided to the log.New invocation. If write permissions were available, this would be set properly by log.SetOutput.

I don't know if this behavior is also present on Windows since I haven't personally tested it. In an out-of-band conversation, @ramiro-gamarra mentioned that this is a Linux-specific issue with this package.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions