mirror of
https://github.com/obgm/libcoap.git
synced 2026-11-09 10:32:53 +03:00
coap_debug.c: Use length returned by print_timestamp()
In theory, print_timestamp() could omit the terminating null byte when the buffer passed as argument is too small or if snprintf() returns -1. To make coap_log_impl() more robust against unforeseen out-of-bounds access, the length returned by print_timestamp() now is passed to fprintf() explicitly.
This commit is contained in:
1 parent
a9d5f07661
commit
620e6fe2d4
1 file changed
+4
-2
+4
-2
@@ -800,12 +800,14 @@ coap_log_impl(coap_log_t level, const char *format, ...) {
|
||||
coap_tick_t now;
|
||||
va_list ap;
|
||||
FILE *log_fd;
|
||||
size_t len;
|
||||
|
||||
log_fd = level <= LOG_CRIT ? COAP_ERR_FD : COAP_DEBUG_FD;
|
||||
|
||||
coap_ticks(&now);
|
||||
if (print_timestamp(timebuf,sizeof(timebuf), now))
|
||||
fprintf(log_fd, "%s ", timebuf);
|
||||
len = print_timestamp(timebuf,sizeof(timebuf), now);
|
||||
if (len)
|
||||
fprintf(log_fd, "%.*s ", (int)len, timebuf);
|
||||
|
||||
if (level <= COAP_LOG_CIPHERS)
|
||||
fprintf(log_fd, "%s ", loglevels[level]);
|
||||
|
||||
Reference in new issue
Block a user