Skip to content

Commit

Permalink
rpcclient: Read first line of cookie instead of trimming space
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyRand committed May 25, 2020
1 parent deb09c7 commit 831de8e
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions rpcclient/cookiefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,27 @@
package rpcclient

import (
"bufio"
"fmt"
"io/ioutil"
"os"
"strings"
)

func readCookieFile(path string) (username, password string, err error) {
b, err := ioutil.ReadFile(path)
f, err := os.Open(path)
if err != nil {
return
}
defer f.Close()

scanner := bufio.NewScanner(f)
scanner.Scan()
err = scanner.Err()
if err != nil {
return
}
s := scanner.Text()

s := strings.TrimSpace(string(b))
parts := strings.SplitN(s, ":", 2)
if len(parts) != 2 {
err = fmt.Errorf("malformed cookie file")
Expand Down

0 comments on commit 831de8e

Please sign in to comment.