Skip to content

Commit

Permalink
Merge pull request #17 from tearfur/malformed-logs
Browse files Browse the repository at this point in the history
fix: malformed logs produced by `struct_utp_context::log()`
  • Loading branch information
ckerr authored Nov 16, 2024
2 parents 2d29ce9 + eedd8b9 commit 490874c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
13 changes: 9 additions & 4 deletions utp_internal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3388,21 +3388,26 @@ void struct_utp_context::log(int level, utp_socket *socket, char const *fmt, ...

va_list va;
va_start(va, fmt);
log_unchecked(socket, fmt, va);
log_impl(socket, fmt, va);
va_end(va);
}

void struct_utp_context::log_unchecked(utp_socket *socket, char const *fmt, ...)
{
va_list va;
va_start(va, fmt);
log_impl(socket, fmt, va);
va_end(va);
}

void struct_utp_context::log_impl(utp_socket *socket, char const *fmt, va_list va)
{
char buf[4096];

va_start(va, fmt);
vsnprintf(buf, 4096, fmt, va);
buf[4095] = '\0';
va_end(va);

utp_call_log(this, socket, (const byte *)buf);
utp_call_log(this, socket, reinterpret_cast<const byte *>(buf));
}

inline bool struct_utp_context::would_log(int level)
Expand Down
3 changes: 3 additions & 0 deletions utp_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ struct struct_utp_context {
bool log_normal:1; // log normal events?
bool log_mtu:1; // log MTU related events?
bool log_debug:1; // log debugging events? (Must also compile with UTP_DEBUG_LOGGING defined)

private:
void log_impl(utp_socket *socket, char const *fmt, va_list va);
};

#endif //__UTP_INTERNAL_H__

0 comments on commit 490874c

Please sign in to comment.