@@ -72,16 +72,17 @@ type Config struct {
72
72
}
73
73
74
74
const (
75
- ageExt = ".age"
76
- agentSocketPath = "socket"
77
- defaultLength = "20"
78
- defaultPattern = "[A-Za-z0-9]"
79
- dirPerms = 0o700
80
- filePerms = 0o600
81
- maxStepsPerChar = 1000
82
- storePath = "store"
83
- version = "0.9.0"
84
- waitForSocket = 3 * time .Second
75
+ ageExt = ".age"
76
+ agentSocketPath = "socket"
77
+ defaultLength = "20"
78
+ defaultPattern = "[A-Za-z0-9]"
79
+ dirPerms = 0o700
80
+ filePerms = 0o600
81
+ maxStepsPerChar = 1000
82
+ nameInvalidChars = `[\n]`
83
+ storePath = "store"
84
+ version = "0.9.0"
85
+ waitForSocket = 3 * time .Second
85
86
86
87
clipEnv = "PAGO_CLIP"
87
88
confirmEnv = "PAGO_CONFIRM"
@@ -124,12 +125,16 @@ func (cmd *AddCmd) Run(config *Config) error {
124
125
printRepr (cmd )
125
126
}
126
127
128
+ file , err := entryFile (config .Store , cmd .Name )
129
+ if err != nil {
130
+ return err
131
+ }
132
+
127
133
if ! cmd .Force && entryExists (config .Store , cmd .Name ) {
128
134
return fmt .Errorf ("entry already exists: %v" , cmd .Name )
129
135
}
130
136
131
137
var password string
132
- var err error
133
138
134
139
if cmd .Multiline {
135
140
fmt .Fprintln (os .Stderr , "Reading password from stdin until EOF:" )
@@ -167,11 +172,6 @@ func (cmd *AddCmd) Run(config *Config) error {
167
172
return err
168
173
}
169
174
170
- file , err := entryFile (config .Store , cmd .Name )
171
- if err != nil {
172
- return nil
173
- }
174
-
175
175
if config .Git {
176
176
if err := commit (
177
177
config .Store ,
@@ -840,6 +840,11 @@ func generatePassword(pattern string, length int) (string, error) {
840
840
841
841
// Map an entry's name to its file path.
842
842
func entryFile (passwordStore , name string ) (string , error ) {
843
+ re := regexp .MustCompile (nameInvalidChars )
844
+ if re .MatchString (name ) {
845
+ return "" , fmt .Errorf ("entry name contains invalid characters matching %s" , nameInvalidChars )
846
+ }
847
+
843
848
file := filepath .Join (passwordStore , name + ageExt )
844
849
845
850
for path := file ; path != "/" ; path = filepath .Dir (path ) {
0 commit comments