Fix segfault when reading/writing from paster

master
Nick Krichevsky 2019-03-10 00:05:29 -05:00
parent 9e329458d6
commit c72589bb7b
1 changed files with 8 additions and 2 deletions

View File

@ -66,12 +66,18 @@ func (p *Paster) prepareAndDo(buffer []byte, action func([]byte) (int, error)) (
// Read gets the contents of the paste from the filesystem
func (p *Paster) Read(buffer []byte) (int, error) {
return p.prepareAndDo(buffer, p.file.Read)
// Wrap in closure to handle the nil file case
return p.prepareAndDo(buffer, func(buffer []byte) (int, error) {
return p.file.Read(buffer)
})
}
// Write sets the contents of the paste.
func (p *Paster) Write(contents []byte) (int, error) {
return p.prepareAndDo(contents, p.file.Write)
// Wrap in closure to handle the nil file case
return p.prepareAndDo(contents, func(buffer []byte) (int, error) {
return p.file.Write(buffer)
})
}
// Close closes the paste