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

x/mod/modfile: crash on AddGoStmt for an empty File #62457

Closed
hajimehoshi opened this issue Sep 5, 2023 · 2 comments
Closed

x/mod/modfile: crash on AddGoStmt for an empty File #62457

hajimehoshi opened this issue Sep 5, 2023 · 2 comments
Labels
FixPending Issues that have a fix which has not yet been reviewed or submitted. help wanted modules NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@hajimehoshi
Copy link
Member

What version of Go are you using (go version)?

$ go version
go version go1.20.4 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/hajimehoshi/Library/Caches/go-build"
GOENV="/Users/hajimehoshi/Library/Application Support/go/env"
GOEXE=""
GOEXPERIMENT=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/hajimehoshi/go/pkg/mod"
GONOPROXY=""
GONOSUMDB=""
GOOS="darwin"
GOPATH="/Users/hajimehoshi/go"
GOPRIVATE=""
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GOVCS=""
GOVERSION="go1.20.4"
GCCGO="gccgo"
GOAMD64="v1"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/dev/null"
GOWORK=""
CGO_CFLAGS="-O2 -g"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-O2 -g"
CGO_FFLAGS="-O2 -g"
CGO_LDFLAGS="-O2 -g"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -arch x86_64 -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/60/khbk2xqn1c5bml1byjn89dwc0000gn/T/go-build3215930630=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Run this program w/ golang.org/x/mod@v0.12.0:

package main

import "golang.org/x/mod/modfile"

func main() {
	f := &modfile.File{}
	f.AddGoStmt("1.20")
}

https://go.dev/play/p/G0zKRp7VvSf

What did you expect to see?

No crash

What did you see instead?

Crash

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

goroutine 1 [running]:
golang.org/x/mod/modfile.(*FileSyntax).addLine(0x0, {0x0, 0x0}, {0xc000060060, 0x2, 0x2})
	/tmp/gopath1845778283/pkg/mod/golang.org/x/mod@v0.12.0/modfile/read.go:108 +0x6e
golang.org/x/mod/modfile.(*File).AddGoStmt(0xc000051eb0, {0x4b93c8, 0x4})
	/tmp/gopath1845778283/pkg/mod/golang.org/x/mod@v0.12.0/modfile/rule.go:980 +0x1c5
main.main()
	/tmp/sandbox2831237298/main.go:7 +0x49
@gopherbot gopherbot added this to the Unreleased milestone Sep 5, 2023
@hajimehoshi
Copy link
Member Author

/CC @bcmills

@hajimehoshi hajimehoshi changed the title x/mod: crash on AddGoStmt for an empty File x/mod/modfile: crash on AddGoStmt for an empty File Sep 5, 2023
@cherrymui cherrymui added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Sep 7, 2023
@bcmills bcmills added help wanted NeedsFix The path to resolution is known, but the work has not been done. FixPending Issues that have a fix which has not yet been reviewed or submitted. modules and removed FixPending Issues that have a fix which has not yet been reviewed or submitted. labels Jan 23, 2024
@gopherbot gopherbot removed the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jan 23, 2024
@gopherbot
Copy link

Change https://go.dev/cl/570115 mentions this issue: modfile: fix crash on AddGoStmt in empty File

@dmitshur dmitshur added the FixPending Issues that have a fix which has not yet been reviewed or submitted. label Mar 8, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
FixPending Issues that have a fix which has not yet been reviewed or submitted. help wanted modules NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

5 participants