Bladeren bron

qcacmn: Return error when unpermitted character is parsed in ini

Currently, when an unpermitted character is added to ini, driver
flags as an unknown config item and continues parsing. This could
be an issue. Change is to return error when invalid character is
parsed in ini.

Change-Id: I0249d187f0e05a31dd256d5de56798a575903e5b
CRs-Fixed: 3354669
David Oladunjoye 2 jaren geleden
bovenliggende
commit
bee501dcb7
4 gewijzigde bestanden met toevoegingen van 97 en 7 verwijderingen
  1. 11 4
      cfg/inc/cfg_ucfg_api.h
  2. 8 1
      cfg/src/cfg.c
  3. 10 1
      qdf/inc/qdf_parse.h
  4. 68 1
      qdf/src/qdf_parse.c

+ 11 - 4
cfg/inc/cfg_ucfg_api.h

@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2018-2019 The Linux Foundation. All rights reserved.
- * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
+ * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  *
  * Permission to use, copy, modify, and/or distribute this software for
  * any purpose with or without fee is hereby granted, provided that the
@@ -180,7 +180,7 @@ QDF_STATUS cfg_section_parse_to_psoc_store(struct wlan_objmgr_psoc *psoc,
 					   const char *section_name);
 
 /**
- * cfg_parse_to_global_store() Parse file @path and update global ini store
+ * cfg_parse_to_global_store() - Parse file @path and update global ini store
  * @path: The full file path of the ini file to parse
  *
  * Return: QDF_STATUS
@@ -188,7 +188,7 @@ QDF_STATUS cfg_section_parse_to_psoc_store(struct wlan_objmgr_psoc *psoc,
 QDF_STATUS cfg_parse_to_global_store(const char *path);
 
 /**
- * cfg_ucfg_store_print() prints the cfg ini/non ini logs
+ * ucfg_cfg_store_print() - prints the cfg ini/non ini logs
  * @psoc: psoc
  *
  * Return: QDF_STATUS
@@ -196,7 +196,7 @@ QDF_STATUS cfg_parse_to_global_store(const char *path);
 QDF_STATUS ucfg_cfg_store_print(struct wlan_objmgr_psoc *psoc);
 
 /**
- * ucfg_cfg_ini_config_print() prints the cfg ini/non ini to buffer
+ * ucfg_cfg_ini_config_print() - prints the cfg ini/non ini to buffer
  * @psoc: psoc
  * @buf: cache to save ini config
  * @plen: the pointer to length
@@ -207,6 +207,13 @@ QDF_STATUS ucfg_cfg_store_print(struct wlan_objmgr_psoc *psoc);
 QDF_STATUS ucfg_cfg_ini_config_print(struct wlan_objmgr_psoc *psoc,
 				     uint8_t *buf, ssize_t *plen,
 				     ssize_t buflen);
+/**
+ * cfg_valid_ini_check() - check ini file for invalid characters
+ * @path: path to ini file
+ *
+ * Return: true if no invalid characters found, false otherwise
+ */
+bool cfg_valid_ini_check(const char *path);
 
 /**
  * cfg_get() - lookup the configured value for @id from @psoc

+ 8 - 1
cfg/src/cfg.c

@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.
- * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
+ * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  *
  * Permission to use, copy, modify, and/or distribute this software for
  * any purpose with or without fee is hereby granted, provided that the
@@ -897,6 +897,13 @@ free_store:
 	return status;
 }
 
+bool cfg_valid_ini_check(const char *path)
+{
+	cfg_enter();
+
+	return qdf_valid_ini_check(path);
+}
+
 void cfg_release(void)
 {
 	cfg_enter();

+ 10 - 1
qdf/inc/qdf_parse.h

@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2018 The Linux Foundation. All rights reserved.
- * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
+ * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  *
  * Permission to use, copy, modify, and/or distribute this software for
  * any purpose with or without fee is hereby granted, provided that the
@@ -88,5 +88,14 @@ qdf_ini_parse(const char *ini_path, void *context,
 QDF_STATUS qdf_ini_section_parse(const char *ini_path, void *context,
 				 qdf_ini_item_cb item_cb,
 				 const char *section_name);
+
+/**
+ * qdf_valid_ini_check() - check ini file for invalid characters
+ * @path: path to ini file
+ *
+ * Return: true if no invalid character found, false otherwise
+ */
+bool qdf_valid_ini_check(const char *path);
+
 #endif /* __QDF_PARSE_H */
 

+ 68 - 1
qdf/src/qdf_parse.c

@@ -1,6 +1,6 @@
 /*
  * Copyright (c) 2018-2021 The Linux Foundation. All rights reserved.
- * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
+ * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
  *
  * Permission to use, copy, modify, and/or distribute this software for
  * any purpose with or without fee is hereby granted, provided that the
@@ -255,3 +255,70 @@ QDF_STATUS qdf_ini_section_parse(const char *ini_path, void *context,
 
 qdf_export_symbol(qdf_ini_section_parse);
 
+static bool is_valid_key(char **main_cursor)
+{
+	char *cursor = *main_cursor;
+
+	while (*cursor != '\0') {
+		unsigned char *val = (unsigned char *)cursor;
+
+		switch (*cursor) {
+		case '\r':
+		case '\n':
+			cursor++;
+			break;
+		case '\0':
+			break;
+		case '=':
+		case '#':
+		case ']':
+		case '[':
+		case '_':
+		case '-':
+		case ' ':
+		case ':':
+			cursor++;
+			break;
+
+		default:
+			if (!isalnum(*val)) {
+				qdf_err("Found invalid character %c", *cursor);
+				return false;
+			}
+			cursor++;
+			break;
+		}
+	}
+	return true;
+}
+
+bool qdf_valid_ini_check(const char  *ini_path)
+{
+	QDF_STATUS status;
+	char *fbuf;
+	char *cursor;
+	bool is_valid = false;
+
+	if (qdf_str_eq(QDF_WIFI_MODULE_PARAMS_FILE, ini_path))
+		status = qdf_module_param_file_read(ini_path, &fbuf);
+	else
+		status = qdf_file_read(ini_path, &fbuf);
+	if (QDF_IS_STATUS_ERROR(status)) {
+		qdf_err("Failed to read *.ini file @ %s", ini_path);
+		return false;
+	}
+
+	/* foreach line */
+	cursor = fbuf;
+
+	is_valid = is_valid_key(&cursor);
+
+	if (qdf_str_eq(QDF_WIFI_MODULE_PARAMS_FILE, ini_path))
+		qdf_module_param_file_free(fbuf);
+	else
+		qdf_file_buf_free(fbuf);
+
+	return is_valid;
+}
+
+qdf_export_symbol(qdf_valid_ini_check);