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

Invalid memory panic when # is in header #13

Closed
ghidinelli opened this issue Apr 3, 2016 · 2 comments
Closed

Invalid memory panic when # is in header #13

ghidinelli opened this issue Apr 3, 2016 · 2 comments

Comments

@ghidinelli
Copy link
Contributor

pgfutter cannot handle a "#" in the header, I suspect because Postgres doesn't support that so pgfutter should sanitize the header names or report an error on attempt. It results in a memory panic (similar to #6):

./pgfutter --table numbers --schema "foo" --host 127.0.0.1 --dbname test --pass 123 csv numbers.csv
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x0 pc=0x7d151]

goroutine 1 [running]:
database/sql.(*Stmt).Exec(0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
    /goroot/src/database/sql/sql.go:1302 +0x3e1
main.NewCSVImport(0xc20805d5e0, 0xc208033426, 0x6, 0xc208033450, 0x7, 0xc2080a4900, 0x9, 0x10, 0x0, 0x0, ...)
    /usr/src/pgfutter/import.go:21 +0xfd
main.importCSV(0x7fff5fbffc69, 0xc, 0xc208104070, 0x6b, 0xc208033426, 0x6, 0xc208033450, 0x7, 0x0, 0x55c470, ...)
    /usr/src/pgfutter/csv.go:127 +0x444
main.func·003(0xc20805ea00)
    /usr/src/pgfutter/pgfutter.go:165 +0x369
github.com/codegangsta/cli.Command.Run(0x380590, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0, 0x3d05f0, 0x18, 0x0, ...)
    /gopath/src/github.com/codegangsta/cli/command.go:174 +0x1403
github.com/codegangsta/cli.(*App).Run(0xc20805e780, 0xc20800a000, 0xd, 0xd, 0x0, 0x0)
    /gopath/src/github.com/codegangsta/cli/app.go:187 +0x1221
main.main()
    /usr/src/pgfutter/pgfutter.go:171 +0xba4

goroutine 5 [syscall]:
os/signal.loop()
    /goroot/src/os/signal/signal_unix.go:21 +0x1f
created by os/signal.init·1
    /goroot/src/os/signal/signal_unix.go:27 +0x35

This file makes it fail:

CarNumber,fname,lname,License #,IsLicenseValid,LicenseStatus,LicenseExpires,HomeRegion,email
0,Randy,Foo,968,True,Competition,"Aug 31, 2016",SouthAtlantic,[email protected]

While this works:

CarNumber,fname,lname,LicenseNo,IsLicenseValid,LicenseStatus,LicenseExpires,HomeRegion,email
0,Randy,Foo,968,True,Competition,"Aug 31, 2016",SouthAtlantic,[email protected]
@lukasmartinelli
Copy link
Owner

Thanks for the very detailled report!
The sanitize function can replace it with "" or _.
https://github.com/lukasmartinelli/pgfutter/blob/master/postgres.go#L46-L68

I can add it but if you want you can replace it as well because it is a straightforward change.

@lukasmartinelli
Copy link
Owner

Resolved by your PR #14
Thanks a lot for the contribution. It will be in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants