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

SIGSEGV using regexp.MatchString() #26259

Closed
ghost opened this issue Jul 7, 2018 · 1 comment
Closed

SIGSEGV using regexp.MatchString() #26259

ghost opened this issue Jul 7, 2018 · 1 comment

Comments

@ghost
Copy link

ghost commented Jul 7, 2018

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

The issue happened on the Go Playground, available at https://play.golang.org/ - According to their documentation, it would be go 1.10.2. Also happened on my computer, running go 1.10.3

Does this issue reproduce with the latest release?

Yes, I reproduce the error on my computer, running go 1.10.3

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

I don't know the configuration of the playground.

As for my computer,

GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/gefn/Library/Caches/go-build"
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/gefn/go"
GORACE=""
GOROOT="/usr/local/Cellar/go/1.10.3/libexec"
GOTMPDIR=""
GOTOOLDIR="/usr/local/Cellar/go/1.10.3/libexec/pkg/tool/darwin_amd64"
GCCGO="gccgo"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/jh/1jnc5vrd14l5b6z35qzm29g80000gn/T/go-build031025937=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

Here is my source code. Note that I used the backtick character because I will need to actually match the + character, and according to a StackOverflow post, to avoid escaping characters, I can use the backtick character to avoid escaping. See https://stackoverflow.com/a/6770913/8908730

Link : https://play.golang.org/p/DmFEAckvcQn

package main

import (
	"fmt"
	"regexp"
)

func foobar(str string) { 
  reg, _ := regexp.Compile(`+[a-z]+`)

  fmt.Println(reg.MatchString(str))            
}

func main() {
  foobar("foo")
}

What did you expect to see?

Either true or false, depending on wether the string matches or not

What did you see instead?

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0xffffffff addr=0x0 pc=0xf6cfc]

goroutine 1 [running]:
regexp.(*Regexp).get(0x0, 0x1050a0d0, 0xb78eafb3, 0xf000008)
	/usr/local/go/src/regexp/regexp.go:211 +0x1c
regexp.(*Regexp).doExecute(0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x121c60, 0x3, 0x0, 0x0, ...)
	/usr/local/go/src/regexp/exec.go:419 +0x40
regexp.(*Regexp).doMatch(0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x121c60, 0x3, 0x1050a0d0, 0x1a0100)
	/usr/local/go/src/regexp/exec.go:411 +0x80
regexp.(*Regexp).MatchString(0x0, 0x121c60, 0x3, 0x14d920, 0x1050a0d0, 0x1a0680)
	/usr/local/go/src/regexp/regexp.go:435 +0x60
main.foobar(0x121c60, 0x3)
	/tmp/sandbox253523048/main.go:11 +0x60
main.main()
	/tmp/sandbox253523048/main.go:15 +0x40
@mvdan
Copy link
Member

mvdan commented Jul 7, 2018

You are not checking the error: https://play.golang.org/p/eCQKgPldY_M

There is no bug in Go here - your program is buggy. In the future,
for questions about Go, use https://golang.org/wiki/Questions.

@mvdan mvdan closed this as completed Jul 7, 2018
@golang golang locked and limited conversation to collaborators Jul 7, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants