[CID-32919, 33501] Fix bug
[platform/upstream/connman.git] / vpn / plugins / ipsec.c
index 148a7ed..617830c 100644 (file)
@@ -267,7 +267,7 @@ static int read_der_file(const char *path, X509 **cert)
        }
 
        *cert = d2i_X509_fp(fp, NULL);
-       if (!fp) {
+       if (!(*cert)) {
                connman_error("Failed to read der file");
                err = -EINVAL;
        }
@@ -295,7 +295,7 @@ static int read_pem_file(const char *path, X509 **cert)
        }
 
        *cert = PEM_read_X509(fp, cert, NULL, NULL);
-       if (!fp) {
+       if (!(*cert)) {
                connman_error("Failed to read pem file");
                err = -EINVAL;
        }
@@ -714,7 +714,7 @@ static int ipsec_load_shared_psk(struct vpn_provider *provider)
 
        if (!provider) {
                connman_error("invalid provider");
-               ret = -EINVAL;
+               return -EINVAL;
        }
 
        data = vpn_provider_get_string(provider, "IPsec.IKEData");
@@ -796,6 +796,12 @@ static char *load_file_from_path(const char *path)
        }
 
        fd = fileno(fp);
+       if (fd == -1) {
+               connman_error("fp is not a valid stream");
+               fclose(fp);
+               return NULL;
+       }
+
        fstat(fd, &st);
        file_size = st.st_size;
        file_buff = g_try_malloc0(sizeof(char)*st.st_size);
@@ -840,8 +846,10 @@ static int ipsec_load_key(struct vpn_provider *provider)
                return 0;
 
        sect = vici_create_section(NULL);
-       if (!sect)
+       if (!sect) {
+               g_free(data);
                return -ENOMEM;
+       }
 
        vici_add_kv(sect, "type", type, NULL);
        vici_add_kv(sect, "data", data, NULL);
@@ -1145,6 +1153,13 @@ static void check_vici_socket(struct ipsec_private_data *data)
        }
 }
 
+static void ipsec_died(struct connman_task *task, int exit_code, void *user_data)
+{
+       DBG("task %p exit_code %d", task, exit_code);
+       unlink(VICI_DEFAULT_URI);
+       vpn_died(task, exit_code, user_data);
+}
+
 static int ipsec_connect(struct vpn_provider *provider,
                        struct connman_task *task, const char *if_name,
                        vpn_provider_connect_cb_t cb, const char *dbus_sender,
@@ -1163,7 +1178,7 @@ static int ipsec_connect(struct vpn_provider *provider,
        /*
         * Start charon daemon using ipsec script of strongSwan.
         */
-       err = connman_task_run(task, vpn_died, provider, NULL, NULL, NULL);
+       err = connman_task_run(task, ipsec_died, provider, NULL, NULL, NULL);
        if (err < 0) {
                connman_error("charon start failed");
                if (cb)