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

Daemon panics if no path is given #1265

Merged
merged 3 commits into from
May 22, 2015

Conversation

travisperson
Copy link
Member

If no path after /ipfs/ or /ipns/ is given, then the daemon will
panic with a slice bounds out of range error. This checks to see if we
have anything after ipfs or ipns.

If no path after `/ipfs/` or `/ipns/` is given, then the daemon will
panic with a slice bounds out of range error. This checks to see if we
have anything after `ipfs` or `ipns`.
@jbenet jbenet added the backlog label May 21, 2015
@whyrusleeping
Copy link
Member

good catch!

@travisperson
Copy link
Member Author

It was actually already there, just removed 13 days ago.

3ead244#diff-f666ab4b28c2e912b2339140db6061eeL50

Might put back in that same logic?

It looks like a pretty complex commit and parts of it might of been removed for a particular reason. The length check needs to be there someplace though I believe still.

@jbenet
Copy link
Member

jbenet commented May 21, 2015

paging @wking and @cryptix -- who touched this part last

@wking
Copy link
Contributor

wking commented May 21, 2015

On Wed, May 20, 2015 at 07:12:43PM -0700, Travis Person wrote:

It was actually already there, just removed 13 days ago.

3ead244#diff-f666ab4b28c2e912b2339140db6061eeL50

Might put back in that same logic?

Oops, sorry about that. And maybe a test to make sure I don't break
this again in a future refactor?

@travisperson
Copy link
Member Author

@wking is adding back these lines alright, or should it be modified?

if len(seg) < 2 || seg[1] == "" { // just "/ipns/"
    return nil, fmt.Errorf("invalid path: %s", string(r.p))
}

@wking
Copy link
Contributor

wking commented May 21, 2015

On Wed, May 20, 2015 at 07:55:10PM -0700, Travis Person wrote:

@wking is adding back these lines alright, or should it be modified?

if len(seg) < 2 || seg[1] == "" { // just "/ipns/"
  return nil, fmt.Errorf("invalid path: %s", string(r.p))
}

Well, r isn't defined anymore, now that resolveRecurse is gone. You
should just use the p from Resolve's arguments. And you'll also
want to restore the "fmt" import. And perhaps the comment should be:

// just "//" without further segments

because the problem isn't restricted to /ipns/ (e.g. it could be
‘/ipfs/’ or in the future maybe ‘/my-wonky-protocol/’).

Added the original logic to check for a invalid path and a simple test.
@jbenet
Copy link
Member

jbenet commented May 21, 2015

this LGTM. will merge after tests

@travisperson
Copy link
Member Author

I agree, I enjoy named errors. We loose the formatting with named errors though. I'm not sure if it's all that important in this case though and am 100% okay with creating a new error instead.

@wking
Copy link
Contributor

wking commented May 21, 2015

On Wed, May 20, 2015 at 09:18:30PM -0700, Travis Person wrote:

I agree, I enjoy named errors. We loose the formatting with named
errors though.

Is there a way around that? I'm not fluent in Go yet, but the idea
behind “does the string form of this error start with …?” seems
straightforward enough. Is there an idiomatic way to ask that? Or is
that not the sort of thing that people do?

@travisperson
Copy link
Member Author

At the very least we could do this:

if !strings.HasPrefix(err.Error(), "invalid path:") {

Which is probably a good idea, as the test I wrote actually fails on core/resolve: no Namesys on IpfsNode - can't resolve ipns entry

@jbenet hold off on merging this.

Cleaned the tests, and actually test for the error.
@jbenet
Copy link
Member

jbenet commented May 21, 2015

(aside: error handling is clunky in general. feels unfinished.)

@jbenet
Copy link
Member

jbenet commented May 21, 2015

@jbenet hold off on merging this.

ack

@travisperson
Copy link
Member Author

As long as there are no further comments I think this is good to go.

@whyrusleeping
Copy link
Member

@travisperson i fixed the namesys issue you were running into.

jbenet added a commit that referenced this pull request May 22, 2015
@jbenet jbenet merged commit 78defff into ipfs:master May 22, 2015
@jbenet jbenet removed the backlog label May 22, 2015
@jbenet
Copy link
Member

jbenet commented May 22, 2015

thanks @travisperson

@jbenet
Copy link
Member

jbenet commented May 22, 2015

@travisperson looks like this PR made osx go tests fail here:

so i reverted :(

previous merge head was 78defff

Also noted commits are behind master. maybe rebase, PR again and see if it does indeed fail? (i don't want to keep introducing intermittent testing failures)

@whyrusleeping
Copy link
Member

the tests passed fine when it merged, and this isnt a thing that can be intermittent.

@travisperson travisperson deleted the bug/panic-on-empty-path branch May 22, 2015 16:04
@travisperson travisperson restored the bug/panic-on-empty-path branch May 22, 2015 16:04
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.

5 participants