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

v1.10.8 break if .pgpass contains empty line #1119

Closed
acoshift opened this issue Apr 16, 2023 · 1 comment · Fixed by #1120
Closed

v1.10.8 break if .pgpass contains empty line #1119

acoshift opened this issue Apr 16, 2023 · 1 comment · Fixed by #1120

Comments

@acoshift
Copy link
Contributor

After I upgrade lib/pq from v1.10.7 to v1.10.8. It's panic every query command with message

runtime error: index out of range [0] with length 0

After investigate I found that if .pgpass contains empty line, It'll error.

Step to reproduce

  1. Create ~/.pgpass with this content
localhost:5432:*:postgres:password

localhost:5432:*:user:password
  1. Set .pgpass permission
$ chmod 600 ~/.pgpass
  1. Run this Go code
package main

import (
	"database/sql"
	"log"

	_ "github.com/lib/pq"
)

func main() {
	db, err := sql.Open("postgres", "postgres://postgres@localhost/postgres?sslmode=disable")
	if err != nil {
		log.Fatalf("Error opening database: %v", err)
	}
	defer db.Close()

	var n int
	err = db.QueryRow(`select 1`).Scan(&n)
	if err != nil {
		log.Fatalf("Error querying database: %v", err)
	}
	log.Printf("n=%d", n)
}
go run .
2023/04/16 15:53:49 Error querying database: runtime error: index out of range [0] with length 0
exit status 1
@KumanekoSakura
Copy link

@otan I upgraded from 1.10.7 to 1.10.8, and found that .pgpass file is no longer processed (regardless of whether .pgpass contains an invalid line).
Like #1120 suggests,

if len(line) != 0 || line[0] != '#' {
	return
}

is by error always true, and

if len(split) == 5 {
	return
}

is by error (as long as line is valid) always true.

Please fix this regression introduced by #1101 and release immediately, or more people will be confused.

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

Successfully merging a pull request may close this issue.

2 participants