Skip to content

Commit 38e19ac

Browse files
leogrpoiana
authored andcommitted
fix(cmd): correct error handling in PSP conversion func
Signed-off-by: Leonardo Grasso <[email protected]>
1 parent ec60f49 commit 38e19ac

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

cmd/convert_psp.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ package cmd
1818

1919
import (
2020
"fmt"
21+
"io"
2122
"os"
2223

24+
"io/ioutil"
25+
2326
converter "github.com/falcosecurity/falcoctl/pkg/converter/psp"
2427
"github.com/kris-nova/logger"
2528
"github.com/spf13/cobra"
2629
"github.com/spf13/viper"
27-
"io/ioutil"
2830
"k8s.io/cli-runtime/pkg/genericclioptions"
2931
)
3032

@@ -84,6 +86,9 @@ func convertPspFalcoRules(pspPath string, rulesPath string) error {
8486
logger.Debug("Reading PSP from %s", pspPath)
8587

8688
psp, err := ioutil.ReadAll(pspFile)
89+
if err != nil && err != io.EOF {
90+
return fmt.Errorf("Could not read PSP file: %s", pspPath)
91+
}
8792

8893
conv, err := converter.NewConverter(debugLog, infoLog, errorLog)
8994
if err != nil {
@@ -95,7 +100,9 @@ func convertPspFalcoRules(pspPath string, rulesPath string) error {
95100
return fmt.Errorf("Could not convert psp file to falco rules: %v", err)
96101
}
97102

98-
err = ioutil.WriteFile(rulesPath, []byte(rules), 0644)
103+
if err = ioutil.WriteFile(rulesPath, []byte(rules), 0644); err != nil {
104+
return fmt.Errorf("Could not write rules to: %s", rulesPath)
105+
}
99106

100107
logger.Debug("Wrote rules to %s", rulesPath)
101108

0 commit comments

Comments
 (0)