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

Fix panic when parsing sftp URIs #592

Merged
merged 10 commits into from Aug 28, 2016
Merged

Fix panic when parsing sftp URIs #592

merged 10 commits into from Aug 28, 2016

Conversation

fd0
Copy link
Member

@fd0 fd0 commented Aug 28, 2016

Closes #587

@wscott
Copy link

wscott commented Aug 28, 2016

my example works well:

$ ./restic -r sftp://p4:backups.restic snapshots
invalid backend "sftp://p4:backups.restic", no directory specified

Thanks.
I see you are still working on the sftp disabled issue.

@fd0
Copy link
Member Author

fd0 commented Aug 28, 2016

Yeah, I've opened an issue at pkg/sftp#133, but until that is implemented we'll just test for the string: 451f812#diff-7a06440ed5a9c66f259b47e47bd6f785R62

@fd0
Copy link
Member Author

fd0 commented Aug 28, 2016

Could you please disable sftp for your NAS again and run restic? Then please report the error message that is returned, thanks!

@wscott
Copy link

wscott commented Aug 28, 2016

Hmm. I disabled stfp and the error detection didn't seem to work on this fix-587 branch.

$ ./restic version
restic 0.2.0 (v0.2.0-162-g451f812)
compiled at 2016-08-28 06:44:15 with go1.6

$ ./restic -r sftp://p4/homes/wscott/backups.restic snapshots
subsystem request failed on channel 0
EOF

Also with it enabled I am getting this. Odd because I thought I get this working eventually on Friday...

$ ./restic -r sftp://p4/homes/wscott/backups.restic snapshots
enter password for repository: 
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x28 pc=0x745bae]

goroutine 1 [running]:
panic(0x9c9200, 0xc82000e1a0)
    /usr/local/go/src/runtime/panic.go:464 +0x3e6
github.com/pkg/sftp.(*File).Write(0x0, 0xc8201882c0, 0xa5, 0xa5, 0xc8221b3130, 0x0, 0x0)
    /tmp/restic-build-428970331/src/github.com/pkg/sftp/client.go:890 +0x4e
restic/backend/sftp.(*SFTP).Save(0xc820162000, 0xa83178, 0x4, 0xc82006c7c0, 0x40, 0xc8201882c0, 0xa5, 0xa5, 0x7f27e4133850, 0xc820014280)
    /tmp/restic-build-428970331/src/restic/backend/sftp/sftp.go:338 +0x393
restic/repository.(*Repository).SaveUnpacked(0xc82006e840, 0xa83178, 0x4, 0xc8200a0090, 0x85, 0x88, 0x2bfffa28df5664a5, 0xb4a6888fae5a6fdc, 0xf1f7e704df07a653, 0x638b8a8706003a3, ...)
    /tmp/restic-build-428970331/src/restic/repository/repository.go:271 +0x245
restic/repository.(*Repository).SaveJSONUnpacked(0xc82006e840, 0xa83178, 0x4, 0xa3c540, 0xc8200b02a0, 0x0, 0x0, 0x0, 0x0, 0x0, ...)
    /tmp/restic-build-428970331/src/restic/repository/repository.go:256 +0x33a
restic.(*Lock).createLock(0xc8200b02a0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0)
    /tmp/restic-build-428970331/src/restic/lock.go:168 +0x8e
restic.newLock(0xc82006e840, 0xc820086000, 0x7f27e41b8528, 0x0, 0x0)
    /tmp/restic-build-428970331/src/restic/lock.go:94 +0x202
restic.NewLock(0xc82006e840, 0x9, 0x0, 0x0)
    /tmp/restic-build-428970331/src/restic/lock.go:61 +0x32
main.lockRepository(0xc82006e840, 0x8ceb00, 0xc8200ed0a0, 0x0, 0x0)
    /tmp/restic-build-428970331/src/cmds/restic/lock.go:35 +0x4f
main.lockRepo(0xc82006e840, 0x25, 0x0, 0x0)
    /tmp/restic-build-428970331/src/cmds/restic/lock.go:22 +0x32
main.CmdSnapshots.Execute(0x0, 0x0, 0x0, 0x0, 0x0, 0xd6f8a0, 0xc8201363f0, 0x0, 0x3, 0x0, ...)
    /tmp/restic-build-428970331/src/cmds/restic/cmd_snapshots.go:81 +0x285
main.(*CmdSnapshots).Execute(0xc820075fb0, 0xc8201363f0, 0x0, 0x3, 0x0, 0x0)
    <autogenerated>:50 +0xc6
github.com/jessevdk/go-flags.(*Parser).ParseArgs(0xc82008a870, 0xc82006c110, 0x3, 0x3, 0x0, 0x0, 0x0, 0x0, 0x0)
    /tmp/restic-build-428970331/src/github.com/jessevdk/go-flags/parser.go:278 +0x8dd
github.com/jessevdk/go-flags.(*Parser).Parse(0xc82008a870, 0x0, 0x0, 0x0, 0x0, 0x0)
    /tmp/restic-build-428970331/src/github.com/jessevdk/go-flags/parser.go:154 +0x9b
main.main()
    /tmp/restic-build-428970331/src/cmds/restic/main.go:32 +0x1e8

Note this last one does require the password so it is getting to the right repo.

I am going to have to run off and won't be back online for another 8 hours.

@wscott
Copy link

wscott commented Aug 28, 2016

Just looked, that second stacktrace is consistent with what I reported Friday. But we expected the 'sftp disabled' case to generate a message and it didn't. I have been using NFS.

@fd0
Copy link
Member Author

fd0 commented Aug 28, 2016

Interesting. I don't see where the error message is generated. The position I identified is slightly different: subsystem request failed on channel 0 vs ssh: subsystem request failed

@fd0
Copy link
Member Author

fd0 commented Aug 28, 2016

Oh wow, the stacktrace is caused by a missing error check in my backend code in src/restic/backend/sftp/sftp.go:

    filename, tmpfile, err := r.tempFile()
    debug.Log("sftp.Save", "save %v (%d bytes) to %v", h, len(p), filename)

    n, err := tmpfile.Write(p)
    if err != nil {
        return err
    }

@fd0
Copy link
Member Author

fd0 commented Aug 28, 2016

Double-Wow, this check was also missing from the local backend. This gets much better error messages for #93!

This yields the error messages for a full backup location:

    panic: write /home/fd0/mnt/temp/tmp/temp-987810174: no space left on device

Closes #540

Also connected to #574
@fd0
Copy link
Member Author

fd0 commented Aug 28, 2016

I've extracted the fixes for the local and sftp backend (the missing error check) into #593 so we can merge them immediately.

@wscott
Copy link

wscott commented Aug 28, 2016

Yup. Much better, the bad URLs give

$ ./restic version
restic 0.2.0 (v0.2.0-162-g451f812)
compiled at 2016-08-28 13:46:49 with go1.6

$ ./restic -r sftp://p4:backups.restic snapshots
invalid backend "sftp://p4:backups.restic", no directory specified

$ ./restic -r sftp://p4/backups.restic snapshots
backups.restic does not exist

With SFTP disabled I still get a poor message:

$ ./restic -r sftp://p4/backups.restic snapshots
subsystem request failed on channel 0
EOF

The invalid memory address still happens when I actually use the right URL with SFTP enabled.

Also add a prefix for all errors written to stderr by the client
@fd0
Copy link
Member Author

fd0 commented Aug 28, 2016

Can you please retry with current commits?

The error message now is:

subprocess ssh: subsystem request failed on channel 1
unable to start the sftp session, error: EOF

@wscott
Copy link

wscott commented Aug 28, 2016

Ah when I use #593 the invalid memory address goes away and was replaced with this:

 $ ./restic -r sftp://p4/homes/wscott/backups.restic snapshots
enter password for repository: 
creating tempfile "homes/wscott/backups.restic/tmp/temp-a3a2a92b9cc67d4f7184" failed: sftp: "Permission denied" (SSH_FX_PERMISSION_DENIED)

But SFTP disabled still looks like this:

$ ./restic -r sftp://p4/homes/wscott/backups.restic snapshots
subsystem request failed on channel 0
EOF

@wscott
Copy link

wscott commented Aug 28, 2016

nevermind

$ ./restic -r sftp://p4/homes/wscott/backups.restic snapshots
subprocess ssh: subsystem request failed on channel 0
unable to start the sftp session, error: EOF

with the fix-587 tip.

Thanks.

@fd0
Copy link
Member Author

fd0 commented Aug 28, 2016

Great, thanks for the confirmation.

For the record: Comment out the sftp line in the sshd_config file of OpenSSH disables sftp, that's what I used for testing:

#Subsystem sftp internal-sftp

@wscott
Copy link

wscott commented Aug 28, 2016

With the proper error messages I was able to fix the settings on my NAS to get closer to the right answer.
However what is this last part?

$ ./restic -r sftp://p4/backups.restic snapshots
enter password for repository: 
ID        Date                 Host        Directory
----------------------------------------------------------------------
c7b5156a  2016-08-26 11:19:38  x99         /home/wscott
                                           /space/wscott
7bf90859  2016-08-27 06:47:43  x99         /home/wscott
8f9003ee  2016-08-27 06:56:29  x99         /space/wscott
f1d206fb  2016-08-28 00:01:23  x99         /home/wscott
63aef99c  2016-08-28 00:13:31  x99         /space/wscott
error in cleanup handler: file does not exist

All commands seem to include that file does not exist message. And it seems to leave a stale lock behind. New issue?

@fd0
Copy link
Member Author

fd0 commented Aug 28, 2016

Yes, new issue. IRC?

@fd0 fd0 merged commit 83924d0 into master Aug 28, 2016
fd0 added a commit that referenced this pull request Aug 28, 2016
Fix panic when parsing sftp URIs
@fd0 fd0 deleted the fix-587 branch August 28, 2016 18:14
@wscott
Copy link

wscott commented Aug 28, 2016

Sorry out of time to play at the moment.

@fd0
Copy link
Member Author

fd0 commented Aug 28, 2016

Nevermind, write a debug log and open a new issue later. Oh, and try unlock.

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.

None yet

2 participants