int __netconfig_hex_str_to_bin(const char *hex, unsigned char *buf, size_t len);
int __netconfig_hex_to_byte(const char *hex);
int __netconfig_hex_char_to_num(char c);
+gboolean __netconfig_is_valid_config_id(const gchar *config_id);
gboolean handle_get_config_ids(Wifi *wifi, GDBusMethodInvocation *context,
const gchar *ifname);
return bits;
}
-static gboolean __netconfig_is_valid_config_id(const gchar *config_id)
+gboolean __netconfig_is_valid_config_id(const gchar *config_id)
{
int length;
return FALSE;
for (int i = 0; i < length; i++) {
- if (!(islower(config_id[i])) &&
- !(isdigit(config_id[i])) &&
- config_id[i] != '_')
+ if (!(isxdigit(config_id[i])) && config_id[i] != '_')
return FALSE;
}
#include <stdio.h>
#include <unistd.h>
#include <sys/stat.h>
+#include <ctype.h>
#include "log.h"
#include "util.h"
#define CONNMAN_CONFIG_FIELD_PVT_KEY_PASSPHRASE "PrivateKeyPassphrase"
#define CONNMAN_CONFIG_FIELD_KEYMGMT_TYPE "KeymgmtType"
+static gboolean __netconfig_is_valid_hex(const gchar *str)
+{
+ int length;
+
+ if (!str)
+ return FALSE;
+
+ length = strlen(str);
+ if (length < 1)
+ return FALSE;
+
+ for (int i = 0; i < length; i++) {
+ if (!(isxdigit(str[i])))
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
static char *__get_encoded_ssid(const char *name)
{
char *str = NULL;
}
}
- if (encoded_ssid == NULL) {
+ if (__netconfig_is_valid_hex(encoded_ssid) == FALSE) {
ERR("Failed to fetch SSID");
goto out;
}
memcpy(mac_str, &profile[strlen(CONNMAN_WIFI_SERVICE_PROFILE_PREFIX)], 12);
mac_str[12] = '\0';
+ if (__netconfig_is_valid_hex(mac_str) == FALSE) {
+ ERR("Failed to fetch mac_str");
+ goto out;
+ }
+
/* Create unique service group name */
group_name = g_strdup_printf("service_%s", encoded_ssid);
if (group_name == NULL) {
while (g_variant_iter_loop(iter, "{ss}", &field, &value)) {
if (g_strcmp0(field, CONNMAN_CONFIG_FIELD_SSID) == 0 ||
g_strcmp0(field, CONNMAN_CONFIG_FIELD_EAP_METHOD) == 0 ||
- g_strcmp0(field, CONNMAN_CONFIG_FIELD_PHASE2) ||
+ g_strcmp0(field, CONNMAN_CONFIG_FIELD_PHASE2) == 0 ||
g_strcmp0(field, CONNMAN_CONFIG_FIELD_KEYMGMT_TYPE) == 0) {
if (value != NULL)
g_key_file_set_string(keyfile, group_name, field, value);
}
ERR("get config_id [%s] from [%s]", config_id, profile);
+ if (__netconfig_is_valid_config_id(config_id) == FALSE) {
+ ERR("Invalid config_id [%s]", config_id);
+ g_free(config_id);
+ return ret;
+ }
+
ret = wifi_config_remove_configuration(interface_name, config_id);
if (ret != TRUE)
ERR("Fail to wifi_config_remove_configuration [%s]", config_id);
int vsie_len = strlen(vsie);
DBG("vsie: %s vsie_len: %d", vsie, vsie_len);
ies_len = (vsie_len % 2) ? ((vsie_len / 2) + 1) : (vsie_len / 2);
- __netconfig_hex_str_to_bin(vsie, ies, ies_len);
+ if (NETCONFIG_MAX_VSIE_LEN >= ies_len)
+ __netconfig_hex_str_to_bin(vsie, ies, ies_len);
}
if (ies[0] == NETCONFIG_VENDOR_SPECIFIC_ID && ies[1] >= 4) {