From: Jason A. Donenfeld Date: Mon, 18 Mar 2019 18:49:25 +0000 (-0600) Subject: ringlogger: document races X-Git-Tag: 0.0.20190319-1~6 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=51822f722a033a481a5e0edcc51e33f5c39e9369;p=thirdparty%2Fwireguard-apple.git ringlogger: document races Signed-off-by: Jason A. Donenfeld --- 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);