Skip to content
Snippets Groups Projects
Commit 8efbd30d authored by Fabian Seidl's avatar Fabian Seidl
Browse files

169 Handling of some vulnerablities after mono

See merge request !259
parent 10622d4d
No related branches found
No related tags found
2 merge requests!259169 Handling of some vulnerablities after mono,!247Develop
Pipeline #98272 passed
...@@ -73,7 +73,10 @@ func init() { ...@@ -73,7 +73,10 @@ func init() {
rootCmd.AddCommand(initCmd) rootCmd.AddCommand(initCmd)
initCmd.Flags().StringVar(&controllerAPIEndpoint, "controller", "gosdn-develop.apps.ocp.fbi.h-da.de:55055", "address of the controller") initCmd.Flags().StringVar(&controllerAPIEndpoint, "controller", "gosdn-develop.apps.ocp.fbi.h-da.de:55055", "address of the controller")
viper.BindPFlag("controllerAPIEndpoint", initCmd.Flags().Lookup("controller")) err := viper.BindPFlag("controllerAPIEndpoint", initCmd.Flags().Lookup("controller"))
if err != nil {
fmt.Fprintln(os.Stderr, "Could not bind controllerAPIEndpoint:", err)
}
// Set controller flag as required (possibly not?) // Set controller flag as required (possibly not?)
//if err := initCmd.MarkFlagRequired("controller"); err != nil { //if err := initCmd.MarkFlagRequired("controller"); err != nil {
......
...@@ -86,7 +86,11 @@ func executeFunc(s string) { ...@@ -86,7 +86,11 @@ func executeFunc(s string) {
return return
} }
rootCmd.SetArgs(strings.Fields(s)) rootCmd.SetArgs(strings.Fields(s))
rootCmd.Execute() err := rootCmd.Execute()
if err != nil {
fmt.Fprintln(os.Stderr, "Could not execute:", err)
}
} }
func flagVisitor(f *pflag.Flag) { func flagVisitor(f *pflag.Flag) {
......
...@@ -35,7 +35,11 @@ var LogLevel logrus.Level ...@@ -35,7 +35,11 @@ var LogLevel logrus.Level
// Init gets called on module import // Init gets called on module import
func Init() { func Init() {
InitializeConfig() err := InitializeConfig()
if err != nil {
log.Error("failed initialization of module import", err)
}
} }
// InitializeConfig loads the configuration // InitializeConfig loads the configuration
......
...@@ -99,7 +99,14 @@ func (s core) DeletePnd(ctx context.Context, request *pb.DeletePndRequest) (*pb. ...@@ -99,7 +99,14 @@ func (s core) DeletePnd(ctx context.Context, request *pb.DeletePndRequest) (*pb.
if err != nil { if err != nil {
return nil, handleRPCError(labels, err) return nil, handleRPCError(labels, err)
} }
pndc.Delete(pndID)
err = pndc.Delete(pndID)
if err != nil {
return &pb.DeletePndResponse{
Timestamp: time.Now().UnixNano(),
Status: pb.Status_STATUS_ERROR,
}, err
}
return &pb.DeletePndResponse{ return &pb.DeletePndResponse{
Timestamp: time.Now().UnixNano(), Timestamp: time.Now().UnixNano(),
......
...@@ -7,6 +7,7 @@ import ( ...@@ -7,6 +7,7 @@ import (
"io" "io"
"os" "os"
"path/filepath" "path/filepath"
"strings"
"time" "time"
"code.fbi.h-da.de/danet/gosdn/controller/metrics" "code.fbi.h-da.de/danet/gosdn/controller/metrics"
...@@ -620,6 +621,15 @@ func saveGenericClientStreamToFile(t GenericGrpcClient, filename string, id uuid ...@@ -620,6 +621,15 @@ func saveGenericClientStreamToFile(t GenericGrpcClient, filename string, id uuid
folderName := viper.GetString("plugin-folder") folderName := viper.GetString("plugin-folder")
path := filepath.Join(folderName, id.String(), filename) path := filepath.Join(folderName, id.String(), filename)
// clean path to prevent attackers to get access to to directories elsewhere on the system
path = filepath.Clean(path)
if !strings.HasPrefix(path, folderName) {
return uuid.Nil, &errors.ErrInvalidParameters{
Func: saveGenericClientStreamToFile,
Param: path,
}
}
// create the directory hierarchy based on the path // create the directory hierarchy based on the path
if err := os.MkdirAll(filepath.Dir(path), 0770); err != nil { if err := os.MkdirAll(filepath.Dir(path), 0770); err != nil {
return uuid.Nil, err return uuid.Nil, err
...@@ -629,7 +639,12 @@ func saveGenericClientStreamToFile(t GenericGrpcClient, filename string, id uuid ...@@ -629,7 +639,12 @@ func saveGenericClientStreamToFile(t GenericGrpcClient, filename string, id uuid
if err != nil { if err != nil {
return uuid.Nil, err return uuid.Nil, err
} }
defer f.Close()
defer func() {
if err := f.Close(); err != nil {
log.Error("error closing file: ", err)
}
}()
// receive byte stream // receive byte stream
for { for {
...@@ -639,11 +654,21 @@ func saveGenericClientStreamToFile(t GenericGrpcClient, filename string, id uuid ...@@ -639,11 +654,21 @@ func saveGenericClientStreamToFile(t GenericGrpcClient, filename string, id uuid
break break
} }
t.CloseSend() t.CloseSend()
closeErr := t.CloseSend()
if closeErr != nil {
return uuid.Nil, closeErr
}
return uuid.Nil, err return uuid.Nil, err
} }
n, err := f.Write(payload.Chunk) n, err := f.Write(payload.Chunk)
if err != nil { if err != nil {
t.CloseSend() t.CloseSend()
closeErr := t.CloseSend()
if closeErr != nil {
return uuid.Nil, closeErr
}
return uuid.Nil, err return uuid.Nil, err
} }
log.WithField("n", n).Trace("wrote bytes") log.WithField("n", n).Trace("wrote bytes")
......
...@@ -56,7 +56,12 @@ func Run(bindAddr string) { ...@@ -56,7 +56,12 @@ func Run(bindAddr string) {
signal.Reset(os.Interrupt) signal.Reset(os.Interrupt)
ctx, cancel := context.WithTimeout(context.Background(), time.Minute) ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
defer cancel() defer cancel()
stopHttpServer(ctx) err := stopHttpServer(ctx)
if err != nil {
log.WithFields(log.Fields{}).Info(err)
}
o.Shutdown(ctx) o.Shutdown(ctx)
}() }()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment