diff --git a/rpcclient/cookiefile.go b/rpcclient/cookiefile.go index b29e29b7..c3f7068b 100644 --- a/rpcclient/cookiefile.go +++ b/rpcclient/cookiefile.go @@ -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")