chore(deps): bump github.com/lib/pq from 1.10.3 to 1.10.7

Bumps [github.com/lib/pq](https://github.com/lib/pq) from 1.10.3 to 1.10.7.
- [Release notes](https://github.com/lib/pq/releases)
- [Commits](https://github.com/lib/pq/compare/v1.10.3...v1.10.7)

---
updated-dependencies:
- dependency-name: github.com/lib/pq
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
This commit is contained in:
dependabot[bot] 2022-11-02 06:29:09 +00:00 committed by TwiN
parent 6e92c0eb40
commit ed3683cb32
13 changed files with 287 additions and 137 deletions

2
go.mod
View File

@ -11,7 +11,7 @@ require (
github.com/go-ping/ping v0.0.0-20210911151512-381826476871
github.com/google/uuid v1.3.0
github.com/gorilla/mux v1.8.0
github.com/lib/pq v1.10.3
github.com/lib/pq v1.10.7
github.com/miekg/dns v1.1.43
github.com/prometheus/client_golang v1.13.0
github.com/wcharczuk/go-chart/v2 v2.1.0

4
go.sum
View File

@ -169,8 +169,8 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/lib/pq v1.10.3 h1:v9QZf2Sn6AmjXtQeFpdoq/eaNtYP6IN+7lcrygsIAtg=
github.com/lib/pq v1.10.3/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/lib/pq v1.10.7 h1:p7ZhMD+KsSRozJr34udlUrhboJwWAgCg34+/ZZNvZZw=
github.com/lib/pq v1.10.7/go.mod h1:AlVN5x4E4T544tWzH6hKfbfQvm3HdbOxrmggDNAPY9o=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-isatty v0.0.14 h1:yVuAays6BHfxijgZPzw+3Zlu5yQgKGP2/hcQbHb7S9Y=
github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94=

4
vendor/github.com/lib/pq/array.go generated vendored
View File

@ -587,8 +587,8 @@ func (a *Int32Array) scanBytes(src []byte) error {
} else {
b := make(Int32Array, len(elems))
for i, v := range elems {
var x int
if x, err = strconv.Atoi(string(v)); err != nil {
x, err := strconv.ParseInt(string(v), 10, 32)
if err != nil {
return fmt.Errorf("pq: parsing array element index %d: %v", i, err)
}
b[i] = int32(x)

161
vendor/github.com/lib/pq/conn.go generated vendored
View File

@ -18,7 +18,7 @@ import (
"path/filepath"
"strconv"
"strings"
"sync/atomic"
"sync"
"time"
"unicode"
@ -31,8 +31,10 @@ var (
ErrNotSupported = errors.New("pq: Unsupported command")
ErrInFailedTransaction = errors.New("pq: Could not complete operation in a failed transaction")
ErrSSLNotSupported = errors.New("pq: SSL is not enabled on the server")
ErrSSLKeyHasWorldPermissions = errors.New("pq: Private key file has group or world access. Permissions should be u=rw (0600) or less")
ErrCouldNotDetectUsername = errors.New("pq: Could not detect default username. Please provide one explicitly")
ErrSSLKeyUnknownOwnership = errors.New("pq: Could not get owner information for private key, may not be properly protected")
ErrSSLKeyHasWorldPermissions = errors.New("pq: Private key has world access. Permissions should be u=rw,g=r (0640) if owned by root, or u=rw (0600), or less")
ErrCouldNotDetectUsername = errors.New("pq: Could not detect default username. Please provide one explicitly")
errUnexpectedReady = errors.New("unexpected ReadyForQuery")
errNoRowsAffected = errors.New("no RowsAffected available after the empty statement")
@ -140,9 +142,10 @@ type conn struct {
saveMessageType byte
saveMessageBuffer []byte
// If true, this connection is bad and all public-facing functions should
// return ErrBadConn.
bad *atomic.Value
// If an error is set, this connection is bad and all public-facing
// functions should return the appropriate error by calling get()
// (ErrBadConn) or getForNext().
err syncErr
// If set, this connection should never use the binary format when
// receiving query results from prepared statements. Only provided for
@ -166,6 +169,40 @@ type conn struct {
gss GSS
}
type syncErr struct {
err error
sync.Mutex
}
// Return ErrBadConn if connection is bad.
func (e *syncErr) get() error {
e.Lock()
defer e.Unlock()
if e.err != nil {
return driver.ErrBadConn
}
return nil
}
// Return the error set on the connection. Currently only used by rows.Next.
func (e *syncErr) getForNext() error {
e.Lock()
defer e.Unlock()
return e.err
}
// Set error, only if it isn't set yet.
func (e *syncErr) set(err error) {
if err == nil {
panic("attempt to set nil err")
}
e.Lock()
defer e.Unlock()
if e.err == nil {
e.err = err
}
}
// Handle driver-side settings in parsed connection string.
func (cn *conn) handleDriverSettings(o values) (err error) {
boolSetting := func(key string, val *bool) error {
@ -287,7 +324,7 @@ func DialOpen(d Dialer, dsn string) (_ driver.Conn, err error) {
if err != nil {
return nil, err
}
c.dialer = d
c.Dialer(d)
return c.open(context.Background())
}
@ -306,12 +343,9 @@ func (c *Connector) open(ctx context.Context) (cn *conn, err error) {
o[k] = v
}
bad := &atomic.Value{}
bad.Store(false)
cn = &conn{
opts: o,
dialer: c.dialer,
bad: bad,
}
err = cn.handleDriverSettings(o)
if err != nil {
@ -516,22 +550,9 @@ func (cn *conn) isInTransaction() bool {
cn.txnStatus == txnStatusInFailedTransaction
}
func (cn *conn) setBad() {
if cn.bad != nil {
cn.bad.Store(true)
}
}
func (cn *conn) getBad() bool {
if cn.bad != nil {
return cn.bad.Load().(bool)
}
return false
}
func (cn *conn) checkIsInTransaction(intxn bool) {
if cn.isInTransaction() != intxn {
cn.setBad()
cn.err.set(driver.ErrBadConn)
errorf("unexpected transaction status %v", cn.txnStatus)
}
}
@ -541,8 +562,8 @@ func (cn *conn) Begin() (_ driver.Tx, err error) {
}
func (cn *conn) begin(mode string) (_ driver.Tx, err error) {
if cn.getBad() {
return nil, driver.ErrBadConn
if err := cn.err.get(); err != nil {
return nil, err
}
defer cn.errRecover(&err)
@ -552,11 +573,11 @@ func (cn *conn) begin(mode string) (_ driver.Tx, err error) {
return nil, err
}
if commandTag != "BEGIN" {
cn.setBad()
cn.err.set(driver.ErrBadConn)
return nil, fmt.Errorf("unexpected command tag %s", commandTag)
}
if cn.txnStatus != txnStatusIdleInTransaction {
cn.setBad()
cn.err.set(driver.ErrBadConn)
return nil, fmt.Errorf("unexpected transaction status %v", cn.txnStatus)
}
return cn, nil
@ -570,8 +591,8 @@ func (cn *conn) closeTxn() {
func (cn *conn) Commit() (err error) {
defer cn.closeTxn()
if cn.getBad() {
return driver.ErrBadConn
if err := cn.err.get(); err != nil {
return err
}
defer cn.errRecover(&err)
@ -592,12 +613,12 @@ func (cn *conn) Commit() (err error) {
_, commandTag, err := cn.simpleExec("COMMIT")
if err != nil {
if cn.isInTransaction() {
cn.setBad()
cn.err.set(driver.ErrBadConn)
}
return err
}
if commandTag != "COMMIT" {
cn.setBad()
cn.err.set(driver.ErrBadConn)
return fmt.Errorf("unexpected command tag %s", commandTag)
}
cn.checkIsInTransaction(false)
@ -606,8 +627,8 @@ func (cn *conn) Commit() (err error) {
func (cn *conn) Rollback() (err error) {
defer cn.closeTxn()
if cn.getBad() {
return driver.ErrBadConn
if err := cn.err.get(); err != nil {
return err
}
defer cn.errRecover(&err)
return cn.rollback()
@ -618,7 +639,7 @@ func (cn *conn) rollback() (err error) {
_, commandTag, err := cn.simpleExec("ROLLBACK")
if err != nil {
if cn.isInTransaction() {
cn.setBad()
cn.err.set(driver.ErrBadConn)
}
return err
}
@ -658,7 +679,7 @@ func (cn *conn) simpleExec(q string) (res driver.Result, commandTag string, err
case 'T', 'D':
// ignore any results
default:
cn.setBad()
cn.err.set(driver.ErrBadConn)
errorf("unknown response for simple query: %q", t)
}
}
@ -680,7 +701,7 @@ func (cn *conn) simpleQuery(q string) (res *rows, err error) {
// the user can close, though, to avoid connections from being
// leaked. A "rows" with done=true works fine for that purpose.
if err != nil {
cn.setBad()
cn.err.set(driver.ErrBadConn)
errorf("unexpected message %q in simple query execution", t)
}
if res == nil {
@ -707,7 +728,7 @@ func (cn *conn) simpleQuery(q string) (res *rows, err error) {
err = parseError(r)
case 'D':
if res == nil {
cn.setBad()
cn.err.set(driver.ErrBadConn)
errorf("unexpected DataRow in simple query execution")
}
// the query didn't fail; kick off to Next
@ -722,7 +743,7 @@ func (cn *conn) simpleQuery(q string) (res *rows, err error) {
// To work around a bug in QueryRow in Go 1.2 and earlier, wait
// until the first DataRow has been received.
default:
cn.setBad()
cn.err.set(driver.ErrBadConn)
errorf("unknown response for simple query: %q", t)
}
}
@ -815,8 +836,8 @@ func (cn *conn) prepareTo(q, stmtName string) *stmt {
}
func (cn *conn) Prepare(q string) (_ driver.Stmt, err error) {
if cn.getBad() {
return nil, driver.ErrBadConn
if err := cn.err.get(); err != nil {
return nil, err
}
defer cn.errRecover(&err)
@ -854,8 +875,8 @@ func (cn *conn) Query(query string, args []driver.Value) (driver.Rows, error) {
}
func (cn *conn) query(query string, args []driver.Value) (_ *rows, err error) {
if cn.getBad() {
return nil, driver.ErrBadConn
if err := cn.err.get(); err != nil {
return nil, err
}
if cn.inCopy {
return nil, errCopyInProgress
@ -888,8 +909,8 @@ func (cn *conn) query(query string, args []driver.Value) (_ *rows, err error) {
// Implement the optional "Execer" interface for one-shot queries
func (cn *conn) Exec(query string, args []driver.Value) (res driver.Result, err error) {
if cn.getBad() {
return nil, driver.ErrBadConn
if err := cn.err.get(); err != nil {
return nil, err
}
defer cn.errRecover(&err)
@ -960,7 +981,7 @@ func (cn *conn) sendSimpleMessage(typ byte) (err error) {
// the message yourself.
func (cn *conn) saveMessage(typ byte, buf *readBuf) {
if cn.saveMessageType != 0 {
cn.setBad()
cn.err.set(driver.ErrBadConn)
errorf("unexpected saveMessageType %d", cn.saveMessageType)
}
cn.saveMessageType = typ
@ -1106,7 +1127,7 @@ func isDriverSetting(key string) bool {
return true
case "password":
return true
case "sslmode", "sslcert", "sslkey", "sslrootcert", "sslinline":
case "sslmode", "sslcert", "sslkey", "sslrootcert", "sslinline", "sslsni":
return true
case "fallback_application_name":
return true
@ -1330,8 +1351,8 @@ func (st *stmt) Close() (err error) {
if st.closed {
return nil
}
if st.cn.getBad() {
return driver.ErrBadConn
if err := st.cn.err.get(); err != nil {
return err
}
defer st.cn.errRecover(&err)
@ -1344,14 +1365,14 @@ func (st *stmt) Close() (err error) {
t, _ := st.cn.recv1()
if t != '3' {
st.cn.setBad()
st.cn.err.set(driver.ErrBadConn)
errorf("unexpected close response: %q", t)
}
st.closed = true
t, r := st.cn.recv1()
if t != 'Z' {
st.cn.setBad()
st.cn.err.set(driver.ErrBadConn)
errorf("expected ready for query, but got: %q", t)
}
st.cn.processReadyForQuery(r)
@ -1364,8 +1385,8 @@ func (st *stmt) Query(v []driver.Value) (r driver.Rows, err error) {
}
func (st *stmt) query(v []driver.Value) (r *rows, err error) {
if st.cn.getBad() {
return nil, driver.ErrBadConn
if err := st.cn.err.get(); err != nil {
return nil, err
}
defer st.cn.errRecover(&err)
@ -1377,8 +1398,8 @@ func (st *stmt) query(v []driver.Value) (r *rows, err error) {
}
func (st *stmt) Exec(v []driver.Value) (res driver.Result, err error) {
if st.cn.getBad() {
return nil, driver.ErrBadConn
if err := st.cn.err.get(); err != nil {
return nil, err
}
defer st.cn.errRecover(&err)
@ -1464,7 +1485,7 @@ func (cn *conn) parseComplete(commandTag string) (driver.Result, string) {
if affectedRows == nil && strings.HasPrefix(commandTag, "INSERT ") {
parts := strings.Split(commandTag, " ")
if len(parts) != 3 {
cn.setBad()
cn.err.set(driver.ErrBadConn)
errorf("unexpected INSERT command tag %s", commandTag)
}
affectedRows = &parts[len(parts)-1]
@ -1476,7 +1497,7 @@ func (cn *conn) parseComplete(commandTag string) (driver.Result, string) {
}
n, err := strconv.ParseInt(*affectedRows, 10, 64)
if err != nil {
cn.setBad()
cn.err.set(driver.ErrBadConn)
errorf("could not parse commandTag: %s", err)
}
return driver.RowsAffected(n), commandTag
@ -1543,8 +1564,8 @@ func (rs *rows) Next(dest []driver.Value) (err error) {
}
conn := rs.cn
if conn.getBad() {
return driver.ErrBadConn
if err := conn.err.getForNext(); err != nil {
return err
}
defer conn.errRecover(&err)
@ -1568,7 +1589,7 @@ func (rs *rows) Next(dest []driver.Value) (err error) {
case 'D':
n := rs.rb.int16()
if err != nil {
conn.setBad()
conn.err.set(driver.ErrBadConn)
errorf("unexpected DataRow after error %s", err)
}
if n < len(dest) {
@ -1762,7 +1783,7 @@ func (cn *conn) readReadyForQuery() {
cn.processReadyForQuery(r)
return
default:
cn.setBad()
cn.err.set(driver.ErrBadConn)
errorf("unexpected message %q; expected ReadyForQuery", t)
}
}
@ -1782,7 +1803,7 @@ func (cn *conn) readParseResponse() {
cn.readReadyForQuery()
panic(err)
default:
cn.setBad()
cn.err.set(driver.ErrBadConn)
errorf("unexpected Parse response %q", t)
}
}
@ -1807,7 +1828,7 @@ func (cn *conn) readStatementDescribeResponse() (paramTyps []oid.Oid, colNames [
cn.readReadyForQuery()
panic(err)
default:
cn.setBad()
cn.err.set(driver.ErrBadConn)
errorf("unexpected Describe statement response %q", t)
}
}
@ -1825,7 +1846,7 @@ func (cn *conn) readPortalDescribeResponse() rowsHeader {
cn.readReadyForQuery()
panic(err)
default:
cn.setBad()
cn.err.set(driver.ErrBadConn)
errorf("unexpected Describe response %q", t)
}
panic("not reached")
@ -1841,7 +1862,7 @@ func (cn *conn) readBindResponse() {
cn.readReadyForQuery()
panic(err)
default:
cn.setBad()
cn.err.set(driver.ErrBadConn)
errorf("unexpected Bind response %q", t)
}
}
@ -1868,7 +1889,7 @@ func (cn *conn) postExecuteWorkaround() {
cn.saveMessage(t, r)
return
default:
cn.setBad()
cn.err.set(driver.ErrBadConn)
errorf("unexpected message during extended query execution: %q", t)
}
}
@ -1881,7 +1902,7 @@ func (cn *conn) readExecuteResponse(protocolState string) (res driver.Result, co
switch t {
case 'C':
if err != nil {
cn.setBad()
cn.err.set(driver.ErrBadConn)
errorf("unexpected CommandComplete after error %s", err)
}
res, commandTag = cn.parseComplete(r.string())
@ -1895,7 +1916,7 @@ func (cn *conn) readExecuteResponse(protocolState string) (res driver.Result, co
err = parseError(r)
case 'T', 'D', 'I':
if err != nil {
cn.setBad()
cn.err.set(driver.ErrBadConn)
errorf("unexpected %q after error %s", t, err)
}
if t == 'I' {
@ -1903,7 +1924,7 @@ func (cn *conn) readExecuteResponse(protocolState string) (res driver.Result, co
}
// ignore any results
default:
cn.setBad()
cn.err.set(driver.ErrBadConn)
errorf("unknown %s response: %q", protocolState, t)
}
}
@ -1999,6 +2020,8 @@ func parseEnviron(env []string) (out map[string]string) {
accrue("sslkey")
case "PGSSLROOTCERT":
accrue("sslrootcert")
case "PGSSLSNI":
accrue("sslsni")
case "PGREQUIRESSL", "PGSSLCRL":
unsupported()
case "PGREQUIREPEER":

View File

@ -7,7 +7,6 @@ import (
"fmt"
"io"
"io/ioutil"
"sync/atomic"
"time"
)
@ -115,7 +114,7 @@ func (cn *conn) watchCancel(ctx context.Context) func() {
}
// Set the connection state to bad so it does not get reused.
cn.setBad()
cn.err.set(ctx.Err())
// At this point the function level context is canceled,
// so it must not be used for the additional network
@ -131,7 +130,7 @@ func (cn *conn) watchCancel(ctx context.Context) func() {
return func() {
select {
case <-finished:
cn.setBad()
cn.err.set(ctx.Err())
cn.Close()
case finished <- struct{}{}:
}
@ -157,11 +156,8 @@ func (cn *conn) cancel(ctx context.Context) error {
defer c.Close()
{
bad := &atomic.Value{}
bad.Store(false)
can := conn{
c: c,
bad: bad,
c: c,
}
err = can.ssl(o)
if err != nil {

View File

@ -27,6 +27,11 @@ func (c *Connector) Connect(ctx context.Context) (driver.Conn, error) {
return c.open(ctx)
}
// Dialer allows change the dialer used to open connections.
func (c *Connector) Dialer(dialer Dialer) {
c.dialer = dialer
}
// Driver returns the underlying driver of this Connector.
func (c *Connector) Driver() driver.Driver {
return &Driver{}

114
vendor/github.com/lib/pq/copy.go generated vendored
View File

@ -1,6 +1,7 @@
package pq
import (
"context"
"database/sql/driver"
"encoding/binary"
"errors"
@ -49,12 +50,14 @@ type copyin struct {
buffer []byte
rowData chan []byte
done chan bool
driver.Result
closed bool
sync.Mutex // guards err
err error
mu struct {
sync.Mutex
err error
driver.Result
}
}
const ciBufferSize = 64 * 1024
@ -98,13 +101,13 @@ awaitCopyInResponse:
err = parseError(r)
case 'Z':
if err == nil {
ci.setBad()
ci.setBad(driver.ErrBadConn)
errorf("unexpected ReadyForQuery in response to COPY")
}
cn.processReadyForQuery(r)
return nil, err
default:
ci.setBad()
ci.setBad(driver.ErrBadConn)
errorf("unknown response for copy query: %q", t)
}
}
@ -123,7 +126,7 @@ awaitCopyInResponse:
cn.processReadyForQuery(r)
return nil, err
default:
ci.setBad()
ci.setBad(driver.ErrBadConn)
errorf("unknown response for CopyFail: %q", t)
}
}
@ -144,7 +147,7 @@ func (ci *copyin) resploop() {
var r readBuf
t, err := ci.cn.recvMessage(&r)
if err != nil {
ci.setBad()
ci.setBad(driver.ErrBadConn)
ci.setError(err)
ci.done <- true
return
@ -166,7 +169,7 @@ func (ci *copyin) resploop() {
err := parseError(&r)
ci.setError(err)
default:
ci.setBad()
ci.setBad(driver.ErrBadConn)
ci.setError(fmt.Errorf("unknown response during CopyIn: %q", t))
ci.done <- true
return
@ -174,46 +177,41 @@ func (ci *copyin) resploop() {
}
}
func (ci *copyin) setBad() {
ci.Lock()
ci.cn.setBad()
ci.Unlock()
func (ci *copyin) setBad(err error) {
ci.cn.err.set(err)
}
func (ci *copyin) isBad() bool {
ci.Lock()
b := ci.cn.getBad()
ci.Unlock()
return b
func (ci *copyin) getBad() error {
return ci.cn.err.get()
}
func (ci *copyin) isErrorSet() bool {
ci.Lock()
isSet := (ci.err != nil)
ci.Unlock()
return isSet
func (ci *copyin) err() error {
ci.mu.Lock()
err := ci.mu.err
ci.mu.Unlock()
return err
}
// setError() sets ci.err if one has not been set already. Caller must not be
// holding ci.Mutex.
func (ci *copyin) setError(err error) {
ci.Lock()
if ci.err == nil {
ci.err = err
ci.mu.Lock()
if ci.mu.err == nil {
ci.mu.err = err
}
ci.Unlock()
ci.mu.Unlock()
}
func (ci *copyin) setResult(result driver.Result) {
ci.Lock()
ci.Result = result
ci.Unlock()
ci.mu.Lock()
ci.mu.Result = result
ci.mu.Unlock()
}
func (ci *copyin) getResult() driver.Result {
ci.Lock()
result := ci.Result
ci.Unlock()
ci.mu.Lock()
result := ci.mu.Result
ci.mu.Unlock()
if result == nil {
return driver.RowsAffected(0)
}
@ -240,13 +238,13 @@ func (ci *copyin) Exec(v []driver.Value) (r driver.Result, err error) {
return nil, errCopyInClosed
}
if ci.isBad() {
return nil, driver.ErrBadConn
if err := ci.getBad(); err != nil {
return nil, err
}
defer ci.cn.errRecover(&err)
if ci.isErrorSet() {
return nil, ci.err
if err := ci.err(); err != nil {
return nil, err
}
if len(v) == 0 {
@ -276,14 +274,51 @@ func (ci *copyin) Exec(v []driver.Value) (r driver.Result, err error) {
return driver.RowsAffected(0), nil
}
// CopyData inserts a raw string into the COPY stream. The insert is
// asynchronous and CopyData can return errors from previous CopyData calls to
// the same COPY stmt.
//
// You need to call Exec(nil) to sync the COPY stream and to get any
// errors from pending data, since Stmt.Close() doesn't return errors
// to the user.
func (ci *copyin) CopyData(ctx context.Context, line string) (r driver.Result, err error) {
if ci.closed {
return nil, errCopyInClosed
}
if finish := ci.cn.watchCancel(ctx); finish != nil {
defer finish()
}
if err := ci.getBad(); err != nil {
return nil, err
}
defer ci.cn.errRecover(&err)
if err := ci.err(); err != nil {
return nil, err
}
ci.buffer = append(ci.buffer, []byte(line)...)
ci.buffer = append(ci.buffer, '\n')
if len(ci.buffer) > ciBufferFlushSize {
ci.flush(ci.buffer)
// reset buffer, keep bytes for message identifier and length
ci.buffer = ci.buffer[:5]
}
return driver.RowsAffected(0), nil
}
func (ci *copyin) Close() (err error) {
if ci.closed { // Don't do anything, we're already closed
return nil
}
ci.closed = true
if ci.isBad() {
return driver.ErrBadConn
if err := ci.getBad(); err != nil {
return err
}
defer ci.cn.errRecover(&err)
@ -299,8 +334,7 @@ func (ci *copyin) Close() (err error) {
<-ci.done
ci.cn.inCopy = false
if ci.isErrorSet() {
err = ci.err
if err := ci.err(); err != nil {
return err
}
return nil

10
vendor/github.com/lib/pq/encode.go generated vendored
View File

@ -422,7 +422,7 @@ func ParseTimestamp(currentLocation *time.Location, str string) (time.Time, erro
if remainderIdx < len(str) && str[remainderIdx] == '.' {
fracStart := remainderIdx + 1
fracOff := strings.IndexAny(str[fracStart:], "-+ ")
fracOff := strings.IndexAny(str[fracStart:], "-+Z ")
if fracOff < 0 {
fracOff = len(str) - fracStart
}
@ -432,7 +432,7 @@ func ParseTimestamp(currentLocation *time.Location, str string) (time.Time, erro
remainderIdx += fracOff + 1
}
if tzStart := remainderIdx; tzStart < len(str) && (str[tzStart] == '-' || str[tzStart] == '+') {
// time zone separator is always '-' or '+' (UTC is +00)
// time zone separator is always '-' or '+' or 'Z' (UTC is +00)
var tzSign int
switch c := str[tzStart]; c {
case '-':
@ -454,7 +454,11 @@ func ParseTimestamp(currentLocation *time.Location, str string) (time.Time, erro
remainderIdx += 3
}
tzOff = tzSign * ((tzHours * 60 * 60) + (tzMin * 60) + tzSec)
} else if tzStart < len(str) && str[tzStart] == 'Z' {
// time zone Z separator indicates UTC is +00
remainderIdx += 1
}
var isoYear int
if isBC {
@ -559,7 +563,7 @@ func parseBytea(s []byte) (result []byte, err error) {
if len(s) < 4 {
return nil, fmt.Errorf("invalid bytea sequence %v", s)
}
r, err := strconv.ParseInt(string(s[1:4]), 8, 9)
r, err := strconv.ParseUint(string(s[1:4]), 8, 8)
if err != nil {
return nil, fmt.Errorf("could not parse bytea value: %s", err.Error())
}

17
vendor/github.com/lib/pq/error.go generated vendored
View File

@ -402,6 +402,11 @@ func (err *Error) Fatal() bool {
return err.Severity == Efatal
}
// SQLState returns the SQLState of the error.
func (err *Error) SQLState() string {
return string(err.Code)
}
// Get implements the legacy PGError interface. New code should use the fields
// of the Error struct directly.
func (err *Error) Get(k byte) (v string) {
@ -444,7 +449,7 @@ func (err *Error) Get(k byte) (v string) {
return ""
}
func (err Error) Error() string {
func (err *Error) Error() string {
return "pq: " + err.Message
}
@ -484,7 +489,7 @@ func (cn *conn) errRecover(err *error) {
case nil:
// Do nothing
case runtime.Error:
cn.setBad()
cn.err.set(driver.ErrBadConn)
panic(v)
case *Error:
if v.Fatal() {
@ -493,10 +498,10 @@ func (cn *conn) errRecover(err *error) {
*err = v
}
case *net.OpError:
cn.setBad()
cn.err.set(driver.ErrBadConn)
*err = v
case *safeRetryError:
cn.setBad()
cn.err.set(driver.ErrBadConn)
*err = driver.ErrBadConn
case error:
if v == io.EOF || v.Error() == "remote error: handshake failure" {
@ -506,13 +511,13 @@ func (cn *conn) errRecover(err *error) {
}
default:
cn.setBad()
cn.err.set(driver.ErrBadConn)
panic(fmt.Sprintf("unknown error: %#v", e))
}
// Any time we return ErrBadConn, we need to remember it since *Tx doesn't
// mark the connection bad in database/sql.
if *err == driver.ErrBadConn {
cn.setBad()
cn.err.set(driver.ErrBadConn)
}
}

11
vendor/github.com/lib/pq/ssl.go generated vendored
View File

@ -8,6 +8,7 @@ import (
"os"
"os/user"
"path/filepath"
"strings"
)
// ssl generates a function to upgrade a net.Conn based on the "sslmode" and
@ -50,6 +51,16 @@ func ssl(o values) (func(net.Conn) (net.Conn, error), error) {
return nil, fmterrorf(`unsupported sslmode %q; only "require" (default), "verify-full", "verify-ca", and "disable" supported`, mode)
}
// Set Server Name Indication (SNI), if enabled by connection parameters.
// By default SNI is on, any value which is not starting with "1" disables
// SNI -- that is the same check vanilla libpq uses.
if sslsni := o["sslsni"]; sslsni == "" || strings.HasPrefix(sslsni, "1") {
// RFC 6066 asks to not set SNI if the host is a literal IP address (IPv4
// or IPv6). This check is coded already crypto.tls.hostnameInSNI, so
// just always set ServerName here and let crypto/tls do the filtering.
tlsConf.ServerName = o["host"]
}
err := sslClientCertificates(&tlsConf, o)
if err != nil {
return nil, err

View File

@ -3,7 +3,28 @@
package pq
import "os"
import (
"errors"
"os"
"syscall"
)
const (
rootUserID = uint32(0)
// The maximum permissions that a private key file owned by a regular user
// is allowed to have. This translates to u=rw.
maxUserOwnedKeyPermissions os.FileMode = 0600
// The maximum permissions that a private key file owned by root is allowed
// to have. This translates to u=rw,g=r.
maxRootOwnedKeyPermissions os.FileMode = 0640
)
var (
errSSLKeyHasUnacceptableUserPermissions = errors.New("permissions for files not owned by root should be u=rw (0600) or less")
errSSLKeyHasUnacceptableRootPermissions = errors.New("permissions for root owned files should be u=rw,g=r (0640) or less")
)
// sslKeyPermissions checks the permissions on user-supplied ssl key files.
// The key file should have very little access.
@ -14,8 +35,59 @@ func sslKeyPermissions(sslkey string) error {
if err != nil {
return err
}
if info.Mode().Perm()&0077 != 0 {
return ErrSSLKeyHasWorldPermissions
err = hasCorrectPermissions(info)
// return ErrSSLKeyHasWorldPermissions for backwards compatability with
// existing code.
if err == errSSLKeyHasUnacceptableUserPermissions || err == errSSLKeyHasUnacceptableRootPermissions {
err = ErrSSLKeyHasWorldPermissions
}
return nil
return err
}
// hasCorrectPermissions checks the file info (and the unix-specific stat_t
// output) to verify that the permissions on the file are correct.
//
// If the file is owned by the same user the process is running as,
// the file should only have 0600 (u=rw). If the file is owned by root,
// and the group matches the group that the process is running in, the
// permissions cannot be more than 0640 (u=rw,g=r). The file should
// never have world permissions.
//
// Returns an error when the permission check fails.
func hasCorrectPermissions(info os.FileInfo) error {
// if file's permission matches 0600, allow access.
userPermissionMask := (os.FileMode(0777) ^ maxUserOwnedKeyPermissions)
// regardless of if we're running as root or not, 0600 is acceptable,
// so we return if we match the regular user permission mask.
if info.Mode().Perm()&userPermissionMask == 0 {
return nil
}
// We need to pull the Unix file information to get the file's owner.
// If we can't access it, there's some sort of operating system level error
// and we should fail rather than attempting to use faulty information.
sysInfo := info.Sys()
if sysInfo == nil {
return ErrSSLKeyUnknownOwnership
}
unixStat, ok := sysInfo.(*syscall.Stat_t)
if !ok {
return ErrSSLKeyUnknownOwnership
}
// if the file is owned by root, we allow 0640 (u=rw,g=r) to match what
// Postgres does.
if unixStat.Uid == rootUserID {
rootPermissionMask := (os.FileMode(0777) ^ maxRootOwnedKeyPermissions)
if info.Mode().Perm()&rootPermissionMask != 0 {
return errSSLKeyHasUnacceptableRootPermissions
}
return nil
}
return errSSLKeyHasUnacceptableUserPermissions
}

View File

@ -1,7 +1,7 @@
// Package pq is a pure Go Postgres driver for the database/sql package.
//go:build aix || darwin || dragonfly || freebsd || linux || nacl || netbsd || openbsd || plan9 || solaris || rumprun || illumos
// +build aix darwin dragonfly freebsd linux nacl netbsd openbsd plan9 solaris rumprun illumos
//go:build aix || darwin || dragonfly || freebsd || (linux && !android) || nacl || netbsd || openbsd || plan9 || solaris || rumprun || illumos
// +build aix darwin dragonfly freebsd linux,!android nacl netbsd openbsd plan9 solaris rumprun illumos
package pq

2
vendor/modules.txt vendored
View File

@ -42,7 +42,7 @@ github.com/gorilla/mux
# github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
## explicit
github.com/kballard/go-shellquote
# github.com/lib/pq v1.10.3
# github.com/lib/pq v1.10.7
## explicit; go 1.13
github.com/lib/pq
github.com/lib/pq/oid