Skip to content

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

@acoshift

Description

@acoshift

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

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