[CID-32919, 33501] Fix bug
[platform/upstream/connman.git] / vpn / plugins / ipsec.c
index 7a2675e..617830c 100644 (file)
@@ -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);