From 00d4e0a7c2bf0f8c145c466e3a92d30051bbe8a3 Mon Sep 17 00:00:00 2001
From: jkito <belter@riseup.net>
Date: Sat, 16 Nov 2024 19:40:02 +0530
Subject: [PATCH] fix crash during start when helper not installed

during initialization setting ctx.bitmask as soon as vpn.Init()
returns and by not returning error from launcher.FirewallStop
this works around the issue where the app crashes because of calling
methods of the Bitmask object which was nil

the launcher.FirewallStop method returned an error when the helper
was not installed
---
 pkg/backend/init.go | 4 ++--
 pkg/vpn/bitmask.go  | 3 +--
 2 files changed, 3 insertions(+), 4 deletions(-)

diff --git a/pkg/backend/init.go b/pkg/backend/init.go
index 6e236abd..7be8b19a 100644
--- a/pkg/backend/init.go
+++ b/pkg/backend/init.go
@@ -74,9 +74,10 @@ func initializeBitmask(errCh chan string, opts *InitOpts) {
 			Err(err).
 			Msg("Could not initialize bitmask")
 		errCh <- err.Error()
-		return
 	}
 
+	ctx.bm = b
+
 	// right now we just get autostart from an init flag,
 	// but we want to be able to persist that option from the preferences
 	// pane
@@ -99,7 +100,6 @@ func initializeBitmask(errCh chan string, opts *InitOpts) {
 		log.Error().Msg("Could not find polkit")
 		errCh <- "nopolkit"
 	}
-	ctx.bm = b
 	ctx.IsReady = true
 }
 
diff --git a/pkg/vpn/bitmask.go b/pkg/vpn/bitmask.go
index bc53112f..5e174cef 100644
--- a/pkg/vpn/bitmask.go
+++ b/pkg/vpn/bitmask.go
@@ -119,8 +119,7 @@ func Init() (*Bitmask, error) {
 		Str("caCertPath", b.getTempCaCertPath()).
 		Msg("Sucessfully wrote OpenVPN CA certificate (hardcoded in the binary, not coming from API)")
 
-	err = b.launch.FirewallStop()
-	if err != nil {
+	if err := b.launch.FirewallStop(); err != nil {
 		log.Warn().
 			Err(err).
 			Msg("Could not stop firewall")
-- 
GitLab