Skip to content

Commit dcf6576

Browse files
committed
Fix unsafe use of pre-runners
1 parent bf5364b commit dcf6576

File tree

9 files changed

+30
-28
lines changed

9 files changed

+30
-28
lines changed

client/commands/commands.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,12 @@ import (
2525
"path/filepath"
2626
"strings"
2727

28+
"github.com/reeflective/team/client"
29+
"github.com/reeflective/team/internal/command"
2830
"github.com/rsteube/carapace"
2931
"github.com/rsteube/carapace/pkg/style"
3032
"github.com/spf13/cobra"
3133
"github.com/spf13/pflag"
32-
33-
"github.com/reeflective/team/client"
34-
"github.com/reeflective/team/internal/command"
3534
)
3635

3736
// Generate returns a command tree to embed in client applications connecting

client/commands/import.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ import (
2222
"encoding/json"
2323
"fmt"
2424

25-
"github.com/sirupsen/logrus"
26-
"github.com/spf13/cobra"
27-
2825
"github.com/reeflective/team/client"
2926
"github.com/reeflective/team/internal/command"
27+
"github.com/sirupsen/logrus"
28+
"github.com/spf13/cobra"
3029
)
3130

3231
func importCmd(cli *client.Client) func(cmd *cobra.Command, args []string) {

client/commands/users.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,10 @@ import (
2323
"time"
2424

2525
"github.com/jedib0t/go-pretty/v6/table"
26-
"github.com/sirupsen/logrus"
27-
"github.com/spf13/cobra"
28-
2926
"github.com/reeflective/team/client"
3027
"github.com/reeflective/team/internal/command"
28+
"github.com/sirupsen/logrus"
29+
"github.com/spf13/cobra"
3130
)
3231

3332
func usersCmd(cli *client.Client) func(cmd *cobra.Command, args []string) error {

client/commands/version.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ import (
2222
"fmt"
2323
"time"
2424

25-
"github.com/sirupsen/logrus"
26-
"github.com/spf13/cobra"
27-
2825
"github.com/reeflective/team/client"
2926
"github.com/reeflective/team/internal/command"
27+
"github.com/sirupsen/logrus"
28+
"github.com/spf13/cobra"
3029
)
3130

3231
func versionCmd(cli *client.Client) func(cmd *cobra.Command, args []string) error {

server/commands/commands.go

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,13 @@ package commands
2121
import (
2222
"fmt"
2323

24-
"github.com/rsteube/carapace"
25-
"github.com/spf13/cobra"
26-
"github.com/spf13/pflag"
27-
2824
"github.com/reeflective/team/client"
2925
cli "github.com/reeflective/team/client/commands"
3026
"github.com/reeflective/team/internal/command"
3127
"github.com/reeflective/team/server"
28+
"github.com/rsteube/carapace"
29+
"github.com/spf13/cobra"
30+
"github.com/spf13/pflag"
3231
)
3332

3433
// Generate returns a "teamserver" command root and its tree for teamserver (server-side) management.
@@ -118,7 +117,12 @@ func serverCommands(server *server.Server, client *client.Client) *cobra.Command
118117
closeComps.PositionalAnyCompletion(carapace.ActionCallback(listenerIDCompleter(client, server)))
119118

120119
closeComps.PreRun(func(cmd *cobra.Command, args []string) {
121-
cmd.PersistentPreRunE(cmd, args)
120+
if cmd.PersistentPreRunE != nil {
121+
cmd.PersistentPreRunE(cmd, args)
122+
}
123+
if cmd.PreRunE != nil {
124+
cmd.PreRunE(cmd, args)
125+
}
122126
})
123127

124128
teamCmd.AddCommand(closeCmd)
@@ -213,7 +217,12 @@ func serverCommands(server *server.Server, client *client.Client) *cobra.Command
213217
rmUserComps.PositionalCompletion(carapace.ActionCallback(userCompleter(client, server)))
214218

215219
rmUserComps.PreRun(func(cmd *cobra.Command, args []string) {
216-
cmd.PersistentPreRunE(cmd, args)
220+
if cmd.PersistentPreRunE != nil {
221+
cmd.PersistentPreRunE(cmd, args)
222+
}
223+
if cmd.PreRunE != nil {
224+
cmd.PreRunE(cmd, args)
225+
}
217226
})
218227

219228
// Import a list of users and their credentials.

server/commands/completers.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,9 @@ import (
2323
"net"
2424
"strings"
2525

26-
"github.com/rsteube/carapace"
27-
2826
"github.com/reeflective/team/client"
2927
"github.com/reeflective/team/server"
28+
"github.com/rsteube/carapace"
3029
)
3130

3231
// interfacesCompleter completes interface addresses on the client host.

server/commands/teamserver.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,12 @@ import (
2828
"strings"
2929

3030
"github.com/jedib0t/go-pretty/v6/table"
31-
"github.com/sirupsen/logrus"
32-
"github.com/spf13/cobra"
33-
3431
"github.com/reeflective/team/internal/command"
3532
"github.com/reeflective/team/internal/log"
3633
"github.com/reeflective/team/internal/systemd"
3734
"github.com/reeflective/team/server"
35+
"github.com/sirupsen/logrus"
36+
"github.com/spf13/cobra"
3837
)
3938

4039
func daemoncmd(serv *server.Server) func(cmd *cobra.Command, args []string) error {
@@ -72,7 +71,7 @@ func daemoncmd(serv *server.Server) func(cmd *cobra.Command, args []string) erro
7271
lport = uint16(serv.GetConfig().DaemonMode.Port)
7372
}
7473

75-
fmt.Fprintf(cmd.OutOrStdout(), "Starting %s teamserver daemon on %s:%d ...", serv.Name(), lhost, lport)
74+
fmt.Fprintf(cmd.OutOrStdout(), "Starting %s teamserver daemon on %s:%d ...\n", serv.Name(), lhost, lport)
7675

7776
// Blocking call, your program will only exit/resume on Ctrl-C/SIGTERM
7877
return serv.ServeDaemon(lhost, lport)

server/commands/user.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,12 @@ import (
88
"path/filepath"
99
"strings"
1010

11-
"github.com/sirupsen/logrus"
12-
"github.com/spf13/cobra"
13-
1411
"github.com/reeflective/team/client"
1512
"github.com/reeflective/team/internal/assets"
1613
"github.com/reeflective/team/internal/command"
1714
"github.com/reeflective/team/server"
15+
"github.com/sirupsen/logrus"
16+
"github.com/spf13/cobra"
1817
)
1918

2019
func createUserCmd(serv *server.Server, cli *client.Client) func(cmd *cobra.Command, args []string) {

server/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ func (ts *Server) ServeDaemon(host string, port uint16, opts ...Options) (err er
142142

143143
err = ts.ListenerStartPersistents()
144144
if err != nil && hostPort.MatchString(err.Error()) {
145-
log.Errorf("Error starting persistent listeners: %s", err)
145+
log.Errorf("Error starting persistent listeners: %s\n", err)
146146
}
147147

148148
done := make(chan bool)

0 commit comments

Comments
 (0)