From df9660df7b93a64dffb2e21912d990139ac4009e Mon Sep 17 00:00:00 2001 From: Darek Stojaczyk Date: Mon, 30 Mar 2020 09:44:51 +0200 Subject: [PATCH] lib/event: fix printing non-null-terminated strings %*s prints at least * characters and may add padding to the string. %.*s prints at most * characters. In a few places we used the first instead of the second and printed some garbage to screen (in the best case...). Change-Id: I97a862be61a5e43aa61e8230044dbd64a9db33bd Signed-off-by: Darek Stojaczyk Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/1569 Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Jim Harris Reviewed-by: Aleksey Marchuk --- lib/event/json_config.c | 4 ++-- test/rpc_client/rpc_client_test.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/event/json_config.c b/lib/event/json_config.c index ba8d2bc19..02dccd789 100644 --- a/lib/event/json_config.c +++ b/lib/event/json_config.c @@ -189,7 +189,7 @@ rpc_client_poller(void *arg) assert(resp); if (resp->error) { - SPDK_ERRLOG("error response: %*s", (int)resp->error->len, (char *)resp->error->start); + SPDK_ERRLOG("error response: %.*s", (int)resp->error->len, (char *)resp->error->start); } if (resp->error && ctx->stop_on_error) { @@ -339,7 +339,7 @@ spdk_app_json_config_load_subsystem_config_entry(void *_ctx) params_end = spdk_json_next(ctx->config_it); assert(params_end != NULL); params_len = params_end->start - ctx->config->start + 1; - SPDK_ERRLOG("Failed to decode config entry: %*s!\n", (int)params_len, (char *)ctx->config_it); + SPDK_ERRLOG("Failed to decode config entry: %.*s!\n", (int)params_len, (char *)ctx->config_it); spdk_app_json_config_load_done(ctx, -EINVAL); goto out; } diff --git a/test/rpc_client/rpc_client_test.c b/test/rpc_client/rpc_client_test.c index 65540d514..4b421f7bb 100644 --- a/test/rpc_client/rpc_client_test.c +++ b/test/rpc_client/rpc_client_test.c @@ -308,7 +308,7 @@ spdk_jsonrpc_client_hook_conn_close(struct spdk_jsonrpc_client *client) /* Check for error response */ if (json_resp->error != NULL) { - SPDK_ERRLOG("Unexpected error response: %*s\n", json_resp->error->len, + SPDK_ERRLOG("Unexpected error response: %.*s\n", json_resp->error->len, (char *)json_resp->error->start); rc = -EIO; goto out;