Skip to content

Commit

Permalink
Reject completely empty documents.
Browse files Browse the repository at this point in the history
This only affects empty YAML files, since only these can contain zero documents.

Signed-off-by: Felix Fontein <felix@fontein.de>
  • Loading branch information
felixfontein committed Sep 21, 2023
1 parent 4472219 commit e422158
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 e422158

Please sign in to comment.