Merge pull request 'Properly remove bad profile dir' (#435) from import_export into master
continuous-integration/drone/push Build is pending Details
continuous-integration/drone/tag Build was killed Details

Reviewed-on: #435
This commit is contained in:
Dan Ballard 2022-03-09 23:58:36 +00:00
commit 9e506e5190
2 changed files with 15 additions and 2 deletions

View File

@ -129,7 +129,7 @@ func (app *application) AddPeerPlugin(onion string, pluginID plugins.PluginID) {
func (app *application) ImportProfile(exportedCwtchFile string, password string) (peer.CwtchPeer, error) {
profileDirectory := path.Join(app.directory, "profiles")
profile, err := peer.ImportProfile(exportedCwtchFile, profileDirectory, password)
if err == nil {
if profile != nil || err == nil {
app.installProfile(profile)
}
return profile, err

View File

@ -5,6 +5,7 @@ import (
"compress/gzip"
"crypto/rand"
"database/sql"
"encoding/hex"
"errors"
"fmt"
"git.openprivacy.ca/openprivacy/log"
@ -191,7 +192,8 @@ func ImportProfile(exportedCwtchFile string, profilesDir string, password string
return profile, err
}
// Otherwise purge
os.RemoveAll(filepath.Join(profilesDir, profileDir))
log.Errorf("error importing profile: %v. removing %s", err, profileDir)
os.RemoveAll(profileDir)
return nil, err
}
return nil, err
@ -237,6 +239,11 @@ func checkCwtchProfileBackupFile(srcFile string) (string, error) {
dir := parts[0]
profileFileType := parts[1]
_, hexErr := hex.DecodeString(dir)
if dir == "." || dir == ".." || len(dir) !=32 || hexErr != nil {
return "", errors.New("invalid profile name")
}
if profileName == "" {
profileName = dir
}
@ -292,6 +299,12 @@ func importCwtchProfileBackupFile(srcFile string, profilesDir string) error {
}
dir := parts[0]
base := parts[1]
_, hexErr := hex.DecodeString(dir)
if dir == "." || dir == ".." || len(dir) != 32 || hexErr != nil {
return errors.New("invalid profile name")
}
if profileName == "" {
profileName = dir
}