Revert "[wpa_supplicant] cumilative patch from commit 3a5d1a7e6"
Revert submission 26533062-Supplicant_merge_June24
Reason for revert: https://b.corp.google.com/issues/349780869
Reverted changes: /q/submissionid:26533062-Supplicant_merge_June24
Change-Id: I4a7a5b8ccb6b4822353bacc29649587cd5a3cb80
diff --git a/src/utils/os_unix.c b/src/utils/os_unix.c
index e5b656a..e721df2 100644
--- a/src/utils/os_unix.c
+++ b/src/utils/os_unix.c
@@ -566,59 +566,39 @@
#ifdef WPA_TRACE
#if defined(WPA_TRACE_BFD) && defined(CONFIG_TESTING_OPTIONS)
-struct wpa_trace_test_fail {
- unsigned int fail_after;
- char pattern[256];
-} wpa_trace_test_fail[5][2];
+char wpa_trace_fail_func[256] = { 0 };
+unsigned int wpa_trace_fail_after;
-int testing_test_fail(const char *tag, bool is_alloc)
+static int testing_fail_alloc(void)
{
- const char *ignore_list[] = {
- "os_malloc", "os_zalloc", "os_calloc", "os_realloc",
- "os_realloc_array", "os_strdup", "os_memdup"
- };
const char *func[WPA_TRACE_LEN];
- size_t i, j, res, len, idx;
+ size_t i, res, len;
char *pos, *next;
int match;
- is_alloc = !!is_alloc;
-
- for (idx = 0; idx < ARRAY_SIZE(wpa_trace_test_fail[is_alloc]); idx++) {
- if (wpa_trace_test_fail[is_alloc][idx].fail_after != 0)
- break;
- }
- if (idx >= ARRAY_SIZE(wpa_trace_test_fail[is_alloc]))
+ if (!wpa_trace_fail_after)
return 0;
res = wpa_trace_calling_func(func, WPA_TRACE_LEN);
i = 0;
-
- if (is_alloc) {
- /* Skip our own stack frame */
+ if (i < res && os_strcmp(func[i], __func__) == 0)
+ i++;
+ if (i < res && os_strcmp(func[i], "os_malloc") == 0)
+ i++;
+ if (i < res && os_strcmp(func[i], "os_zalloc") == 0)
+ i++;
+ if (i < res && os_strcmp(func[i], "os_calloc") == 0)
+ i++;
+ if (i < res && os_strcmp(func[i], "os_realloc") == 0)
+ i++;
+ if (i < res && os_strcmp(func[i], "os_realloc_array") == 0)
+ i++;
+ if (i < res && os_strcmp(func[i], "os_strdup") == 0)
+ i++;
+ if (i < res && os_strcmp(func[i], "os_memdup") == 0)
i++;
- /* Skip allocation helpers */
- for (j = 0; j < ARRAY_SIZE(ignore_list) && i < res; j++) {
- if (os_strcmp(func[i], ignore_list[j]) == 0)
- i++;
- }
- } else {
- /* Not allocation, we might have a tag, if so, replace our
- * own stack frame with the tag, otherwise skip it.
- */
- if (tag)
- func[0] = tag;
- else
- i++;
- }
-
- pos = wpa_trace_test_fail[is_alloc][idx].pattern;
-
- /* The prefixes mean:
- * - '=': The function needs to be next in the backtrace
- * - '?': The function is optionally present in the backtrace
- */
+ pos = wpa_trace_fail_func;
match = 0;
while (i < res) {
@@ -658,10 +638,10 @@
if (!match)
return 0;
- wpa_trace_test_fail[is_alloc][idx].fail_after--;
- if (wpa_trace_test_fail[is_alloc][idx].fail_after == 0) {
- wpa_printf(MSG_INFO, "TESTING: fail at %s",
- wpa_trace_test_fail[is_alloc][idx].pattern);
+ wpa_trace_fail_after--;
+ if (wpa_trace_fail_after == 0) {
+ wpa_printf(MSG_INFO, "TESTING: fail allocation at %s",
+ wpa_trace_fail_func);
for (i = 0; i < res; i++)
wpa_printf(MSG_INFO, "backtrace[%d] = %s",
(int) i, func[i]);
@@ -672,83 +652,90 @@
}
-int testing_set_fail_pattern(bool is_alloc, char *patterns)
+char wpa_trace_test_fail_func[256] = { 0 };
+unsigned int wpa_trace_test_fail_after;
+
+int testing_test_fail(void)
{
-#ifdef WPA_TRACE_BFD
- char *token, *context = NULL;
- size_t idx;
+ const char *func[WPA_TRACE_LEN];
+ size_t i, res, len;
+ char *pos, *next;
+ int match;
- is_alloc = !!is_alloc;
+ if (!wpa_trace_test_fail_after)
+ return 0;
- os_memset(wpa_trace_test_fail[is_alloc], 0,
- sizeof(wpa_trace_test_fail[is_alloc]));
+ res = wpa_trace_calling_func(func, WPA_TRACE_LEN);
+ i = 0;
+ if (i < res && os_strcmp(func[i], __func__) == 0)
+ i++;
- idx = 0;
- while ((token = str_token(patterns, " \n\r\t", &context)) &&
- idx < ARRAY_SIZE(wpa_trace_test_fail[is_alloc])) {
- wpa_trace_test_fail[is_alloc][idx].fail_after = atoi(token);
- token = os_strchr(token, ':');
- if (!token) {
- os_memset(wpa_trace_test_fail[is_alloc], 0,
- sizeof(wpa_trace_test_fail[is_alloc]));
- return -1;
+ pos = wpa_trace_test_fail_func;
+
+ match = 0;
+ while (i < res) {
+ int allow_skip = 1;
+ int maybe = 0;
+
+ if (*pos == '=') {
+ allow_skip = 0;
+ pos++;
+ } else if (*pos == '?') {
+ maybe = 1;
+ pos++;
}
+ next = os_strchr(pos, ';');
+ if (next)
+ len = next - pos;
+ else
+ len = os_strlen(pos);
+ if (os_memcmp(pos, func[i], len) != 0) {
+ if (maybe && next) {
+ pos = next + 1;
+ continue;
+ }
+ if (allow_skip) {
+ i++;
+ continue;
+ }
+ return 0;
+ }
+ if (!next) {
+ match = 1;
+ break;
+ }
+ pos = next + 1;
+ i++;
+ }
+ if (!match)
+ return 0;
- os_strlcpy(wpa_trace_test_fail[is_alloc][idx].pattern,
- token + 1,
- sizeof(wpa_trace_test_fail[is_alloc][0].pattern));
- idx++;
+ wpa_trace_test_fail_after--;
+ if (wpa_trace_test_fail_after == 0) {
+ wpa_printf(MSG_INFO, "TESTING: fail at %s",
+ wpa_trace_test_fail_func);
+ for (i = 0; i < res; i++)
+ wpa_printf(MSG_INFO, "backtrace[%d] = %s",
+ (int) i, func[i]);
+ return 1;
}
return 0;
-#else /* WPA_TRACE_BFD */
- return -1;
-#endif /* WPA_TRACE_BFD */
}
+#else
-int testing_get_fail_pattern(bool is_alloc, char *buf, size_t buflen)
-{
-#ifdef WPA_TRACE_BFD
- size_t idx, ret;
- char *pos = buf;
- char *end = buf + buflen;
-
- is_alloc = !!is_alloc;
-
- for (idx = 0; idx < ARRAY_SIZE(wpa_trace_test_fail[is_alloc]); idx++) {
- if (wpa_trace_test_fail[is_alloc][idx].pattern[0] == '\0')
- break;
-
- ret = os_snprintf(pos, end - pos, "%s%u:%s",
- pos == buf ? "" : " ",
- wpa_trace_test_fail[is_alloc][idx].fail_after,
- wpa_trace_test_fail[is_alloc][idx].pattern);
- if (os_snprintf_error(end - pos, ret))
- break;
- pos += ret;
- }
-
- return pos - buf;
-#else /* WPA_TRACE_BFD */
- return -1;
-#endif /* WPA_TRACE_BFD */
-}
-
-#else /* defined(WPA_TRACE_BFD) && defined(CONFIG_TESTING_OPTIONS) */
-
-static inline int testing_test_fail(const char *tag, bool is_alloc)
+static inline int testing_fail_alloc(void)
{
return 0;
}
-
#endif
void * os_malloc(size_t size)
{
struct os_alloc_trace *a;
- if (testing_test_fail(NULL, true))
+ if (testing_fail_alloc())
return NULL;
a = malloc(sizeof(*a) + size);