jamesog / tarsnapmanager

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Segfaults if no arguments given

vendion opened this issue · comments

On line 180 flag.Args() is assumed to always have at least on item. This causes tarsnapmanager to segfault, instead of hitting the default case on line 200. Instead of getting arguments from the command line it should probably grab the full slice and check if the length of the slice is greater than or equal to 1.

Hi, are you sure about this? https://github.com/jamesog/tarsnapmanager/blob/master/tsm.go#L176-L179 checks if os.Args is less than 2 and exits if not.

$ cat .tsmrc
KeepWeeks: 1
KeepMonths: 1
BackupDirs:
  - /tmp
$ tarsnapmanager
Date: 2016-11-25
Expire week: 2016-11-18
Expire month: 2016-10-25

Missing action

Can you show me how to reproduce this, please?

Fairly certain that is the cause, although I also have to pass a flag to it as well as I don't have the tsmrc file in my home directory.

I've only tested this on Arch Linux using Go 1.7.3 and I'm 2/2 on reproducing this behaviour

[vendion@Vili][~]% cat /etc/tarsnap/tsmrc
TarsnapBin: /usr/bin/tarsnap
TarsnapArgs:
  - "--quiet"
ExcludeFile: /etc/tarsnap/tarsnap.exclude
BackupDirs:
  - /etc
  - /var
  - /home
  - /root
KeepWeeks: 5
KeepMonths: 24
ExpireBackups: true
[vendion@Vili][~]% sudo tarsnapmanager -c /etc/tarsnap/tsmrc
Date: 2016-11-25
Expire week: 2016-10-21
Expire month: 2014-11-25

panic: runtime error: index out of range

goroutine 1 [running]:
panic(0x4d3b60, 0xc42000e100)
	/usr/lib/go/src/runtime/panic.go:500 +0x1a1
main.main()
	/home/vendion/gocode/src/github.com/jamesog/tarsnapmanager/tsm.go:180 +0xdd6

Ah, I see the problem. I misunderstood you to mean passing no flags at all was causing the panic. Yep, that's totally valid.

Thanks for the report. Nice to know someone else has tried using this. :-)