Skip to content

Commit

Permalink
Merge pull request #1290 from felixfontein/empty
Browse files Browse the repository at this point in the history
Do not crash if an empty YAML file is encrypted
  • Loading branch information
felixfontein authored Sep 21, 2023
2 parents 4472219 + e422158 commit b7da2fc
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/sops/codes/codes.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ const (
ConfigFileNotFound int = 61
KeyboardInterrupt int = 85
InvalidTreePathFormat int = 91
NeedAtLeastOneDocument int = 92
NoFileSpecified int = 100
CouldNotRetrieveKey int = 128
NoEncryptionKeyFound int = 111
Expand Down
3 changes: 3 additions & 0 deletions cmd/sops/encrypt.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ func encrypt(opts encryptOpts) (encryptedFile []byte, err error) {
if err != nil {
return nil, common.NewExitError(fmt.Sprintf("Error unmarshalling file: %s", err), codes.CouldNotReadInputFile)
}
if len(branches) < 1 {
return nil, common.NewExitError("File cannot be completely empty, it must contain at least one document", codes.NeedAtLeastOneDocument)
}
if err := ensureNoMetadata(opts, branches[0]); err != nil {
return nil, common.NewExitError(err, codes.FileAlreadyEncrypted)
}
Expand Down

0 comments on commit b7da2fc

Please sign in to comment.