Skip to content

Commit

Permalink
Fix incorrect log format strings
Browse files Browse the repository at this point in the history
Fix a number of instances of incorrect format strings, and missing
parameters, in the logging code.

The core logging function is now adorned with the proper GCC function
attributes, preventing future log formatting issues of this nature.

None of these bugs are likely to have caused any crashes or other
issues (other than malformed log messages) in any released version of
XCM.

Signed-off-by: Mattias Rönnblom <[email protected]>
  • Loading branch information
m-ronnblom committed Nov 28, 2024
1 parent a7f77d6 commit ea84edf
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 11 deletions.
4 changes: 3 additions & 1 deletion libxcm/core/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,5 +40,7 @@ bool log_is_enabled(enum log_type type);

void __log_event(enum log_type type, const char *file, int line,
const char *function, struct xcm_socket *s,
const char *format, ...);
const char *format, ...)
__attribute__((format (printf, 6, 7)));

#endif
4 changes: 2 additions & 2 deletions libxcm/core/log_attr_tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
log_attr_type_name(actual_type))

#define LOG_ATTR_TREE_NODE_IS_NOT_VALUE(s, path_str) \
log_debug_sock(s, "Attribute at \"%s\" is a dictionary or list.")
log_debug_sock(s, "Attribute at \"%s\" is a dictionary or list.", path_str)

#define LOG_ATTR_TREE_NON_EXISTENT(s, name) \
log_debug_sock(s, "Attribute \"%s\" does not exist.", name)
Expand Down Expand Up @@ -66,7 +66,7 @@
} while (0)

#define LOG_ATTR_TREE_NODE_IS_NOT_LIST(s, path_str) \
log_debug_sock(s, "Attribute at \"%s\" is not a list.")
log_debug_sock(s, "Attribute at \"%s\" is not a list.", path_str)

#define LOG_ATTR_TREE_LIST_LEN_RESULT(s, attr_name, len) \
log_debug_sock(s, "Length of \"%s\" is %d.", attr_name, len)
Expand Down
4 changes: 2 additions & 2 deletions libxcm/tp/common/log_tp.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
"layer.")

#define LOG_SEND_BUF_LINGER(conn_sock, left) \
log_debug_sock(conn_sock, "%zd bytes not yet delivered to lower " \
log_debug_sock(conn_sock, "%d bytes not yet delivered to lower " \
"layer.", left)

#define LOG_FILL_BUFFER_ATTEMPT(conn_sock, len) \
Expand Down Expand Up @@ -226,7 +226,7 @@
len)

#define LOG_RCV_MSG(conn_sock, len) \
log_debug_sock(conn_sock, "Received a complete %d byte message from " \
log_debug_sock(conn_sock, "Received a complete %zd byte message from " \
"lower layer.", len)

#define LOG_RCV_MSG_TRUNCATED(conn_sock, capacity, len) \
Expand Down
4 changes: 2 additions & 2 deletions libxcm/tp/tcp/xcm_tp_btcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ static int btcp_send(struct xcm_socket *__restrict s,
int rc = send(bts->fd, buf, len, MSG_NOSIGNAL);

if (rc > 0) {
LOG_SEND_ACCEPTED(s, buf, rc);
LOG_SEND_ACCEPTED(s, buf, (size_t)rc);
XCM_TP_CNT_BYTES_INC(bts->conn.cnts, from_app, rc);

LOG_LOWER_DELIVERED_PART(s, rc);
Expand Down Expand Up @@ -979,7 +979,7 @@ static int set_dns_algorithm_attr(struct xcm_socket *s, void *context,
enum tconnect_algorithm algorithm = tconnect_algorithm_enum(value);

if (algorithm == tconnect_algorithm_none) {
LOG_INVALID_DNS_ALGORITHM(s, value);
LOG_INVALID_DNS_ALGORITHM(s, (const char *)value);
errno = EINVAL;
return -1;
}
Expand Down
4 changes: 2 additions & 2 deletions libxcm/tp/tls/log_tls.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
ut_aprintf(buf, sizeof(buf), "; CRL \"%s\"", \
item_unsensitive_data(crl)); \
ut_aprintf(buf, sizeof(buf), "."); \
log_debug_sock(s, buf); \
log_debug_sock(s, "%s", buf); \
} while (0)

#define LOG_TLS_CREATING_CTX(s, cert, key, tc, crl) \
Expand Down Expand Up @@ -142,7 +142,7 @@ void hash_description(uint8_t *hash, size_t hash_len, char *buf);
ut_aprintf(buf, sizeof(buf), "; CRL \"%s\"", \
item_unsensitive_data(crl)); \
ut_aprintf(buf, sizeof(buf), " %s %s.", event, hash_desc); \
log_debug_sock(s, buf); \
log_debug_sock(s, "%s", buf); \
} while (0)

#define LOG_TLS_CTX_HASH(s, cert, key, tc, crl, hash, hash_size) \
Expand Down
2 changes: 1 addition & 1 deletion libxcm/tp/tls/xcm_tp_btls.c
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,7 @@ static int btls_send(struct xcm_socket *__restrict s,
UT_RESTORE_ERRNO(write_errno);

if (rc > 0) {
LOG_SEND_ACCEPTED(s, buf, rc);
LOG_SEND_ACCEPTED(s, buf, (size_t)rc);
XCM_TP_CNT_BYTES_INC(bts->conn.cnts, from_app, rc);

LOG_LOWER_DELIVERED_PART(s, rc);
Expand Down
2 changes: 1 addition & 1 deletion libxcm/tp/ux/xcm_tp_ux.c
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ static int ux_receive(struct xcm_socket *__restrict s,
int rc = recv(us->fd, buf, capacity, MSG_TRUNC);

if (rc > 0) {
LOG_RCV_MSG(s, rc);
LOG_RCV_MSG(s, (size_t)rc);
XCM_TP_CNT_MSG_INC(us->cnts, from_lower, rc);
LOG_APP_DELIVERED(s, rc);
XCM_TP_CNT_MSG_INC(us->cnts, to_app, rc);
Expand Down

0 comments on commit ea84edf

Please sign in to comment.