mirror of
https://github.com/linux-can/can-utils.git
synced 2026-11-04 15:31:10 +01:00
isobusfs: fix printf format specifiers in log messages
Several log messages used format specifiers which did not match the types of the provided arguments (e.g. %d or %i for size_t/ssize_t, %ld for int64_t/time_t and size_t for the '.*' precision). On 64 bit hosts (and for int64_t/time_t on 32 bit hosts) this leads to wrong output or undefined behaviour when the log level is enabled. Additionally the seek response position was compared to the requested offset without le32toh() conversion which fails on big endian hosts. Fix the format specifiers and add the missing le32toh() conversion. Assisted-by: Claude:claude-opus-5-5 Signed-off-by: Oliver Hartkopp <socketcan@hartkopp.net>
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
// SPDX-FileCopyrightText: 2023 Oleksij Rempel <linux@rempel-privat.de>
|
// SPDX-FileCopyrightText: 2023 Oleksij Rempel <linux@rempel-privat.de>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
|
#include <inttypes.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
@@ -95,7 +96,7 @@ int isobusfs_cli_ccm_send(struct isobusfs_priv *priv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (time_diff < -ISOBUSFS_CM_F_FS_STATUS_RATE_JITTER) {
|
if (time_diff < -ISOBUSFS_CM_F_FS_STATUS_RATE_JITTER) {
|
||||||
pr_warn("too late to send next fs status message: %ld ms",
|
pr_warn("too late to send next fs status message: %" PRId64 " ms",
|
||||||
time_diff);
|
time_diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,7 +153,7 @@ static int isobusfs_cli_rx_fs_status(struct isobusfs_priv *priv,
|
|||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
if (msg->len != sizeof(*fs_status)) {
|
if (msg->len != sizeof(*fs_status)) {
|
||||||
pr_warn("wrong message length: %d", msg->len);
|
pr_warn("wrong message length: %zd", msg->len);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,7 +179,7 @@ static int isobusfs_cli_rx_fs_property_res(struct isobusfs_priv *priv,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (msg->len != sizeof(*fs_prop)) {
|
if (msg->len != sizeof(*fs_prop)) {
|
||||||
pr_warn("wrong message length: %d", msg->len);
|
pr_warn("wrong message length: %zd", msg->len);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ int isobusfs_cli_ccd_req(struct isobusfs_priv *priv, const char *name,
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (name_len > ISOBUSFS_MAX_PATH_NAME_LENGTH) {
|
if (name_len > ISOBUSFS_MAX_PATH_NAME_LENGTH) {
|
||||||
pr_warn("path name too long: %i, max is %i", name_len,
|
pr_warn("path name too long: %zu, max is %i", name_len,
|
||||||
ISOBUSFS_MAX_PATH_NAME_LENGTH);
|
ISOBUSFS_MAX_PATH_NAME_LENGTH);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -286,7 +286,7 @@ int isobusfs_cli_fa_of_req(struct isobusfs_priv *priv, const char *name,
|
|||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
if (name_len > ISOBUSFS_MAX_PATH_NAME_LENGTH) {
|
if (name_len > ISOBUSFS_MAX_PATH_NAME_LENGTH) {
|
||||||
pr_warn("path name too long: %i, max is %i", name_len,
|
pr_warn("path name too long: %zu, max is %i", name_len,
|
||||||
ISOBUSFS_MAX_PATH_NAME_LENGTH);
|
ISOBUSFS_MAX_PATH_NAME_LENGTH);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -547,9 +547,9 @@ isobusfs_cli_ls_handle_seek_dir_sent(struct isobusfs_priv *priv,
|
|||||||
if (isobusfs_cli_int_is_error(priv, 0, res->error_code, res->tan))
|
if (isobusfs_cli_int_is_error(priv, 0, res->error_code, res->tan))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
||||||
if (res->position != ctx->offset) {
|
if (le32toh(res->position) != ctx->offset) {
|
||||||
pr_int("Failed to seek to position %zu, got %zu\n",
|
pr_int("Failed to seek to position %zu, got %u\n",
|
||||||
ctx->offset, res->position);
|
ctx->offset, le32toh(res->position));
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -868,7 +868,7 @@ static void isobusfs_cli_process_ls_command(struct isobusfs_priv *priv,
|
|||||||
ctx->handle, NULL, NULL);
|
ctx->handle, NULL, NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
pr_int("Entries found: %i\n", ctx->entry_count);
|
pr_int("Entries found: %zu\n", ctx->entry_count);
|
||||||
priv->int_busy = false;
|
priv->int_busy = false;
|
||||||
isobusfs_cli_ls_free_ctx(ctx);
|
isobusfs_cli_ls_free_ctx(ctx);
|
||||||
isobusfs_cli_promt(priv);
|
isobusfs_cli_promt(priv);
|
||||||
|
|||||||
@@ -443,8 +443,8 @@ void isobusfs_dump_tx_data(const struct isobusfs_buf_log *buffer)
|
|||||||
for (j = 0; j < ISOBUSFS_MIN_TRANSFER_LENGH; ++j)
|
for (j = 0; j < ISOBUSFS_MIN_TRANSFER_LENGH; ++j)
|
||||||
snprintf(data_str + j * 3, 4, "%02X ", entry->data[j]);
|
snprintf(data_str + j * 3, 4, "%02X ", entry->data[j]);
|
||||||
|
|
||||||
pr_debug("Entry %u: %s Timestamp: %ld.%09ld\n", i, data_str,
|
pr_debug("Entry %u: %s Timestamp: %lld.%09ld\n", i, data_str,
|
||||||
entry->ts.tv_sec, entry->ts.tv_nsec);
|
(long long)entry->ts.tv_sec, entry->ts.tv_nsec);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ int isobusfs_srv_fss_send(struct isobusfs_srv_priv *priv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (time_diff < -ISOBUSFS_CM_F_FS_STATUS_RATE_JITTER) {
|
if (time_diff < -ISOBUSFS_CM_F_FS_STATUS_RATE_JITTER) {
|
||||||
pr_warn("too late to send next fs status message: %ld ms",
|
pr_warn("too late to send next fs status message: %" PRId64 " ms",
|
||||||
time_diff);
|
time_diff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -132,7 +132,7 @@ int isobusfs_check_current_dir_access(struct isobusfs_srv_priv *priv,
|
|||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
pr_debug("convert ISOBUS FS path to linux path: %.*s -> %s",
|
pr_debug("convert ISOBUS FS path to linux path: %.*s -> %s",
|
||||||
path_size, path, linux_path);
|
(int)path_size, path, linux_path);
|
||||||
|
|
||||||
ret = isobusfs_cmn_dh_validate_dir_path(linux_path, false);
|
ret = isobusfs_cmn_dh_validate_dir_path(linux_path, false);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
|
|||||||
@@ -287,7 +287,7 @@ static int isobusfs_srv_fa_open_file(struct isobusfs_srv_priv *priv,
|
|||||||
return ret;
|
return ret;
|
||||||
|
|
||||||
pr_debug("convert ISOBUS FS path to linux path: %.*s -> %s",
|
pr_debug("convert ISOBUS FS path to linux path: %.*s -> %s",
|
||||||
path_len, path, linux_path);
|
(int)path_len, path, linux_path);
|
||||||
|
|
||||||
/* Determine open flags based on the requested access type */
|
/* Determine open flags based on the requested access type */
|
||||||
switch (flags & ISOBUSFS_FA_OPEN_MASK) {
|
switch (flags & ISOBUSFS_FA_OPEN_MASK) {
|
||||||
@@ -847,7 +847,7 @@ send_response:
|
|||||||
goto free_res;
|
goto free_res;
|
||||||
}
|
}
|
||||||
|
|
||||||
pr_debug("> tx: Read File Response. Error code: %d (%s), read size: %d",
|
pr_debug("> tx: Read File Response. Error code: %d (%s), read size: %zd",
|
||||||
error_code, isobusfs_error_to_str(error_code), readed_size);
|
error_code, isobusfs_error_to_str(error_code), readed_size);
|
||||||
|
|
||||||
free_res:
|
free_res:
|
||||||
|
|||||||
Reference in New Issue
Block a user