Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

check if we can decode an error before trying #108

Merged
merged 3 commits into from
Aug 10, 2018
Merged

Conversation

Stebalien
Copy link
Member

avoids a nil pointer dereference

fixes ipfs/kubo#4998

@ghost ghost assigned Stebalien May 5, 2018
@ghost ghost added the status/in-progress In progress label May 5, 2018
@Stebalien Stebalien requested a review from keks May 5, 2018 01:12
@BlinkyStitt
Copy link

Thanks for the fast response!

cli/parse.go Outdated
@@ -15,7 +15,7 @@ import (
"github.com/ipfs/go-ipfs-cmds"
logging "github.com/ipfs/go-log"

osh "gx/ipfs/QmXuBJ7DR6k3rmUEKtvVMhwjmXDuJgXXPUt4LQXKBMsU93/go-os-helper"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something had gone rouge here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think importing the github path is okay, and the package is in the gx deps. I think I would remove the blank line above, though, or move logging below the blank line.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@keks fixed

Copy link
Contributor

@keks keks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for stalling this that long. Are you sure checking res.dec == nil is enough? I think there are cases where this is valid state.

@@ -210,6 +210,8 @@ func parseResponse(httpRes *http.Response, req *cmds.Request) (cmds.Response, er
}
e.Message = string(mes)
e.Code = cmdkit.ErrNormal
case res.dec == nil:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, we also use res.dec == nil to check whether the response is a io.Reader-style byte stream here:

if res.dec == nil {
, doesn't that mean that there are valid cases for the decoder being nil?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a raw bytes error?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what you mean. Can you elaborate?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This switch is trying to decode an error. Currently, it handles plain-text error responses, and "encoded" error responses (e.g., JSON). I don't think there are any valid cases where res.dec is nil and contentType isn't plain (for errors, at least).

cli/parse.go Outdated
@@ -15,7 +15,7 @@ import (
"github.com/ipfs/go-ipfs-cmds"
logging "github.com/ipfs/go-log"

osh "gx/ipfs/QmXuBJ7DR6k3rmUEKtvVMhwjmXDuJgXXPUt4LQXKBMsU93/go-os-helper"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think importing the github path is okay, and the package is in the gx deps. I think I would remove the blank line above, though, or move logging below the blank line.

@Stebalien Stebalien merged commit eaf81d2 into master Aug 10, 2018
@ghost ghost removed the status/in-progress In progress label Aug 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ipfs commands panic when HTTP_PROXY set
4 participants