fix: locking the session object when it's read by the api module (fixes #349)

This commit is contained in:
evilsocket 2018-09-27 15:25:35 +02:00
parent 7951981815
commit 7b7739358d
2 changed files with 15 additions and 0 deletions

View file

@ -186,6 +186,9 @@ func (api *RestAPI) sessionRoute(w http.ResponseWriter, r *http.Request) {
return return
} }
session.I.Lock()
defer session.I.Unlock()
path := r.URL.String() path := r.URL.String()
switch { switch {
case path == "/api/session": case path == "/api/session":

View file

@ -108,6 +108,18 @@ func New() (*Session, error) {
return s, nil return s, nil
} }
func (s *Session) Lock() {
s.Env.Lock()
s.Lan.Lock()
s.WiFi.Lock()
}
func (s *Session) Unlock() {
s.Env.Unlock()
s.Lan.Unlock()
s.WiFi.Unlock()
}
func (s *Session) Module(name string) (err error, mod Module) { func (s *Session) Module(name string) (err error, mod Module) {
for _, m := range s.Modules { for _, m := range s.Modules {
if m.Name() == name { if m.Name() == name {