#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <ctype.h>
#include <sys/types.h>
#include <dirent.h>
#include <sys/stat.h>
#define MAC_ADDRESS_LENGTH 12
#define WIFI_PREFIX_LENGTH MAC_ADDRESS_LENGTH + 6 /* wifi_485a3f2f506a_ */
#define PROFILE_PREFIX_LENGTH WIFI_PREFIX_LENGTH + 21 /* /net/connman/service/wifi_485a3f2f506a_ */
+#define WIFI_CONFIG_ID_LENGTH 82 /* SSID(in hex) + "_managed_ieee8021x" */
#define WIFI_MAC_PATH_LENGTH 64
#define WIFI_MAC_ADDR_LENGTH 17
return bits;
}
+gboolean __netconfig_is_valid_config_id(const gchar *config_id)
+{
+ int length;
+
+ if (!config_id)
+ return FALSE;
+
+ length = strlen(config_id);
+ if (length < 1 || length > WIFI_CONFIG_ID_LENGTH)
+ return FALSE;
+
+ for (int i = 0; i < length; i++) {
+ if (!(islower(config_id[i])) &&
+ !(isdigit(config_id[i])) &&
+ config_id[i] != '_')
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
gboolean handle_save_configuration(Wifi *wifi, GDBusMethodInvocation *context,
const gchar *ifname, const gchar *config_id, GVariant *configuration)
{
gchar *group_name = NULL;
int order = 0;
- if ((wifi == NULL) || (config_id == NULL) || (configuration == NULL)) {
+ if ((wifi == NULL) ||
+ (__netconfig_is_valid_config_id(config_id) == FALSE) ||
+ (configuration == NULL)) {
ERR("Invalid parameter");
netconfig_error_invalid_parameter(context);
return TRUE;