aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2019-03-18 12:49:25 -0600
committerJason A. Donenfeld <Jason@zx2c4.com>2019-03-18 12:50:00 -0600
commit2e86e5ac35405187d2f38ceaf6ba474312196be0 (patch)
tree8c1beb370602550b4736b5858f47d49c76eaa423
parentmacOS: Tunnels list: Double-click to activate / deactivate (diff)
downloadwireguard-apple-2e86e5ac35405187d2f38ceaf6ba474312196be0.tar.xz
wireguard-apple-2e86e5ac35405187d2f38ceaf6ba474312196be0.zip
ringlogger: document races
-rw-r--r--WireGuard/Shared/Logging/ringlogger.c3
1 files changed, 3 insertions, 0 deletions
diff --git a/WireGuard/Shared/Logging/ringlogger.c b/WireGuard/Shared/Logging/ringlogger.c
index 440a269..563483a 100644
--- a/WireGuard/Shared/Logging/ringlogger.c
+++ b/WireGuard/Shared/Logging/ringlogger.c
@@ -42,11 +42,14 @@ void write_msg_to_log(struct log *log, const char *tag, const char *msg)
struct log_line *line;
struct timespec ts;
+ // Race: This isn't synchronized with the fetch_add below, so items might be slightly out of order.
clock_gettime(CLOCK_REALTIME, &ts);
+ // Race: More than MAX_LINES writers and this will clash.
index = atomic_fetch_add(&log->next_index, 1);
line = &log->lines[index % MAX_LINES];
+ // Race: Before this line executes, we'll display old data after new data.
atomic_store(&line->time_ns, 0);
memset(line->line, 0, MAX_LOG_LINE_LENGTH);