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/common.h b/src/utils/common.h
index 079f90e..bede21e 100644
--- a/src/utils/common.h
+++ b/src/utils/common.h
@@ -9,7 +9,6 @@
#ifndef COMMON_H
#define COMMON_H
-#include "includes.h"
#include "os.h"
#if defined(__linux__) || defined(__GLIBC__)
@@ -442,13 +441,6 @@
#define BIT(x) (1U << (x))
#endif
-#ifndef MIN
-#define MIN(a, b) ((a) < (b) ? (a) : (b))
-#endif
-#ifndef MAX
-#define MAX(a, b) (((a) > (b)) ? (a) : (b))
-#endif
-
/*
* Definitions for sparse validation
* (http://kernel.org/pub/linux/kernel/people/josh/sparse/)
@@ -551,11 +543,6 @@
return a[0] & 0x01;
}
-static inline bool ether_addr_equal(const u8 *a, const u8 *b)
-{
- return os_memcmp(a, b, ETH_ALEN) == 0;
-}
-
#define broadcast_ether_addr (const u8 *) "\xff\xff\xff\xff\xff\xff"
#include "wpa_debug.h"
diff --git a/src/utils/os.h b/src/utils/os.h
index 1bbaea3..21ba5c3 100644
--- a/src/utils/os.h
+++ b/src/utils/os.h
@@ -108,26 +108,6 @@
}
-static inline void os_reltime_add_ms(struct os_reltime *ts, int ms)
-{
- ts->usec += ms * 1000;
- while (ts->usec >= 1000000) {
- ts->sec++;
- ts->usec -= 1000000;
- }
- while (ts->usec < 0) {
- ts->sec--;
- ts->usec += 1000000;
- }
-}
-
-
-static inline int os_reltime_in_ms(struct os_reltime *ts)
-{
- return ts->sec * 1000 + ts->usec / 1000;
-}
-
-
static inline int os_reltime_initialized(struct os_reltime *t)
{
return t->sec != 0 || t->usec != 0;
@@ -687,24 +667,14 @@
#if defined(WPA_TRACE_BFD) && defined(CONFIG_TESTING_OPTIONS)
-#define TEST_FAIL() testing_test_fail(NULL, false)
-#define TEST_FAIL_TAG(tag) testing_test_fail(tag, false)
-int testing_test_fail(const char *tag, bool is_alloc);
-int testing_set_fail_pattern(bool is_alloc, char *patterns);
-int testing_get_fail_pattern(bool is_alloc, char *buf, size_t buflen);
+#define TEST_FAIL() testing_test_fail()
+int testing_test_fail(void);
+extern char wpa_trace_fail_func[256];
+extern unsigned int wpa_trace_fail_after;
+extern char wpa_trace_test_fail_func[256];
+extern unsigned int wpa_trace_test_fail_after;
#else
#define TEST_FAIL() 0
-#define TEST_FAIL_TAG(tag) 0
-static inline int testing_set_fail_pattern(bool is_alloc, char *patterns)
-{
- return -1;
-}
-
-static inline int testing_get_fail_pattern(bool is_alloc, char *buf,
- size_t buflen)
-{
- return -1;
-}
#endif
#endif /* OS_H */
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);
diff --git a/src/utils/trace.c b/src/utils/trace.c
index 7c9a17f..8f12da8 100644
--- a/src/utils/trace.c
+++ b/src/utils/trace.c
@@ -197,7 +197,7 @@
if (abfd == NULL)
return;
- data.pc = (uintptr_t) ((u8 *) pc - start_offset);
+ data.pc = (bfd_hostptr_t) ((u8 *) pc - start_offset);
data.found = FALSE;
bfd_map_over_sections(abfd, find_addr_sect, &data);
@@ -238,7 +238,7 @@
if (abfd == NULL)
return NULL;
- data.pc = (uintptr_t) ((u8 *) pc - start_offset);
+ data.pc = (bfd_hostptr_t) ((u8 *) pc - start_offset);
data.found = FALSE;
bfd_map_over_sections(abfd, find_addr_sect, &data);
@@ -310,7 +310,7 @@
for (i = 0; i < btrace_num; i++) {
struct bfd_data data;
- data.pc = (uintptr_t) ((u8 *) btrace_res[i] - start_offset);
+ data.pc = (bfd_hostptr_t) ((u8 *) btrace_res[i] - start_offset);
data.found = FALSE;
bfd_map_over_sections(abfd, find_addr_sect, &data);