From bc756e3dbd0ebb884e9354fd829316c6284e8d5b Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Mon, 27 Aug 2018 12:03:40 -0700 Subject: [PATCH] Fix cp crash when resuming from session (#2520) We should make sure to handle errors properly when reading from the session and also parsing. Current master ignores all these situations which leads to crash, this PR handles this to avoid nil pointer crashes. --- cmd/cp-main.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/cmd/cp-main.go b/cmd/cp-main.go index d03217d2..f040ba61 100644 --- a/cmd/cp-main.go +++ b/cmd/cp-main.go @@ -338,9 +338,19 @@ func doCopySession(session *sessionV8) error { gracefulStop() return } + + if e := urlScanner.Err(); e != nil { + // Error while reading. quit immediately + gracefulStop() + return + } + var cpURLs URLs // Unmarshal copyURLs from each line. - json.Unmarshal([]byte(urlScanner.Text()), &cpURLs) + if e := json.Unmarshal([]byte(urlScanner.Text()), &cpURLs); e != nil { + errorIf(probe.NewError(e), "Unable to unmarshal %s", urlScanner.Text()) + continue + } // Save total count. cpURLs.TotalCount = session.Header.TotalObjects