mirror of
https://github.com/rclone/rclone.git
synced 2024-11-25 09:54:44 +01:00
hasher: fix invalid memory address error when MaxAge == 0
When f.opt.MaxAge == 0, f.db is never set, however several methods later assume it is set and attempt to access it, causing an invalid memory address error. This change fixes the issue in a few spots (there may still be others I haven't yet encountered.)
This commit is contained in:
parent
3bf8c877c3
commit
3ca766b2f1
@ -80,6 +80,14 @@ func (f *Fs) dbDump(ctx context.Context, full bool, root string) error {
|
|||||||
}
|
}
|
||||||
root = fspath.JoinRootPath(remoteFs.Root(), f.Root())
|
root = fspath.JoinRootPath(remoteFs.Root(), f.Root())
|
||||||
}
|
}
|
||||||
|
if f.db == nil {
|
||||||
|
if f.opt.MaxAge == 0 {
|
||||||
|
fs.Errorf(f, "db not found. (disabled with max_age = 0)")
|
||||||
|
} else {
|
||||||
|
fs.Errorf(f, "db not found.")
|
||||||
|
}
|
||||||
|
return kv.ErrInactive
|
||||||
|
}
|
||||||
op := &kvDump{
|
op := &kvDump{
|
||||||
full: full,
|
full: full,
|
||||||
root: root,
|
root: root,
|
||||||
|
@ -418,7 +418,9 @@ func (f *Fs) DirMove(ctx context.Context, src fs.Fs, srcRemote, dstRemote string
|
|||||||
|
|
||||||
// Shutdown the backend, closing any background tasks and any cached connections.
|
// Shutdown the backend, closing any background tasks and any cached connections.
|
||||||
func (f *Fs) Shutdown(ctx context.Context) (err error) {
|
func (f *Fs) Shutdown(ctx context.Context) (err error) {
|
||||||
|
if f.db != nil {
|
||||||
err = f.db.Stop(false)
|
err = f.db.Stop(false)
|
||||||
|
}
|
||||||
if do := f.Fs.Features().Shutdown; do != nil {
|
if do := f.Fs.Features().Shutdown; do != nil {
|
||||||
if err2 := do(ctx); err2 != nil {
|
if err2 := do(ctx); err2 != nil {
|
||||||
err = err2
|
err = err2
|
||||||
|
@ -60,9 +60,11 @@ func (f *Fs) testUploadFromCrypt(t *testing.T) {
|
|||||||
assert.NotNil(t, dst)
|
assert.NotNil(t, dst)
|
||||||
|
|
||||||
// check that hash was created
|
// check that hash was created
|
||||||
|
if f.opt.MaxAge > 0 {
|
||||||
hash, err = f.getRawHash(ctx, hashType, fileName, anyFingerprint, longTime)
|
hash, err = f.getRawHash(ctx, hashType, fileName, anyFingerprint, longTime)
|
||||||
assert.NoError(t, err)
|
assert.NoError(t, err)
|
||||||
assert.NotEmpty(t, hash)
|
assert.NotEmpty(t, hash)
|
||||||
|
}
|
||||||
//t.Logf("hash is %q", hash)
|
//t.Logf("hash is %q", hash)
|
||||||
_ = operations.Purge(ctx, f, dirName)
|
_ = operations.Purge(ctx, f, dirName)
|
||||||
}
|
}
|
||||||
|
@ -37,4 +37,9 @@ func TestIntegration(t *testing.T) {
|
|||||||
opt.QuickTestOK = true
|
opt.QuickTestOK = true
|
||||||
}
|
}
|
||||||
fstests.Run(t, &opt)
|
fstests.Run(t, &opt)
|
||||||
|
// test again with MaxAge = 0
|
||||||
|
if *fstest.RemoteName == "" {
|
||||||
|
opt.ExtraConfig = append(opt.ExtraConfig, fstests.ExtraConfigItem{Name: "TestHasher", Key: "max_age", Value: "0"})
|
||||||
|
fstests.Run(t, &opt)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -216,7 +216,7 @@ func (db *DB) loop() {
|
|||||||
|
|
||||||
// Do a key-value operation and return error when done
|
// Do a key-value operation and return error when done
|
||||||
func (db *DB) Do(write bool, op Op) error {
|
func (db *DB) Do(write bool, op Op) error {
|
||||||
if db.queue == nil {
|
if db == nil || db.queue == nil {
|
||||||
return ErrInactive
|
return ErrInactive
|
||||||
}
|
}
|
||||||
r := &request{
|
r := &request{
|
||||||
|
Loading…
Reference in New Issue
Block a user