From f96cb9f810fdc6e4b45a647556a12e3e888a375d Mon Sep 17 00:00:00 2001 From: gichan2-jang Date: Mon, 11 Sep 2023 16:54:19 +0900 Subject: [PATCH] [Coverity] Use snprintf instead of sprintf Let's use safer form of the sprintf() function. Signed-off-by: gichan2-jang --- c/src/ml-api-remote-service.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/c/src/ml-api-remote-service.c b/c/src/ml-api-remote-service.c index 58152a2c..0c4227ef 100644 --- a/c/src/ml-api-remote-service.c +++ b/c/src/ml-api-remote-service.c @@ -20,6 +20,8 @@ #include "ml-api-service.h" #include "ml-api-service-private.h" +#define MAX_PORT_NUM_LEN 6U + /** * @brief Data struct for options. */ @@ -114,17 +116,17 @@ _mlrs_get_edge_info (ml_option_h option, edge_info_s * edge_info) static void _mlrs_set_edge_info (edge_info_s * edge_info, nns_edge_h edge_h) { - char port[6]; + char port[MAX_PORT_NUM_LEN] = { 0, }; nns_edge_set_info (edge_h, "HOST", edge_info->host); - sprintf (port, "%u", edge_info->port); + g_snprintf (port, MAX_PORT_NUM_LEN, "%u", edge_info->port); nns_edge_set_info (edge_h, "PORT", port); if (edge_info->topic) nns_edge_set_info (edge_h, "TOPIC", edge_info->topic); nns_edge_set_info (edge_h, "DEST_HOST", edge_info->dest_host); - sprintf (port, "%u", edge_info->dest_port); + g_snprintf (port, MAX_PORT_NUM_LEN, "%u", edge_info->dest_port); nns_edge_set_info (edge_h, "DEST_PORT", port); }