From: Cheoleun Moon Date: Tue, 7 Sep 2021 04:46:01 +0000 (+0900) Subject: Ensure null-terminated string X-Git-Tag: submit/tizen/20210907.051033^0 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a8a75aa7f23735ecb075c5bf5a60677e47fe6251;p=platform%2Fcore%2Fapi%2Fvine.git Ensure null-terminated string Change-Id: I9dc10563bf3b321bfdca92d581fe491ca15a84e6 Signed-off-by: Cheoleun Moon --- diff --git a/src/vine-disc.cpp b/src/vine-disc.cpp index 084172d..cc994ff 100755 --- a/src/vine-disc.cpp +++ b/src/vine-disc.cpp @@ -231,16 +231,25 @@ static void __discovered_cb(void *plugin_handle, bool available, discovered_event->available = available; strncpy(discovered_event->service_type, service_type, VINE_MAX_SERVICE_TYPE_LEN); + discovered_event->service_type[VINE_MAX_SERVICE_TYPE_LEN] = 0; strncpy(discovered_event->service_name, service_name, VINE_MAX_SERVICE_NAME_LEN); + discovered_event->service_type[VINE_MAX_SERVICE_NAME_LEN] = 0; strncpy(discovered_event->iface_name, iface_name, IF_NAMESIZE); - if (host_name != NULL) + discovered_event->iface_name[IF_NAMESIZE] = 0; + if (host_name != NULL) { strncpy(discovered_event->host_name, host_name, VINE_MAX_HOST_NAME_LEN); - else + discovered_event->host_name[VINE_MAX_HOST_NAME_LEN] = 0; + } + else { memset(discovered_event->host_name, 0, VINE_MAX_HOST_NAME_LEN + 1); - if (mac != NULL) + } + if (mac != NULL) { strncpy(discovered_event->mac, mac, VINE_MAC_LEN); - else + discovered_event->mac[VINE_MAC_LEN] = 0; + } + else { memset(discovered_event->mac, 0, VINE_MAC_LEN + 1); + } discovered_event->port = port; discovered_event->attributes = attr; diff --git a/src/vine-dp.cpp b/src/vine-dp.cpp index d1b883b..c9475ee 100755 --- a/src/vine-dp.cpp +++ b/src/vine-dp.cpp @@ -330,8 +330,8 @@ static void _service_discovered_cb(vine_disc_h disc, bool available, const char *host_name, const char *mac, int port, const map &attr, const char *iface_name, int more_coming, void *user_data) { - VINE_LOGD("%s is discovered. %s", - service_name, available ? "available" : "not available"); + VINE_LOGD("service_type[%s] service_name[%s] is discovered. %s", + service_type, service_name, available ? "available" : "not available"); if (!user_data || !available) return; diff --git a/src/vine-service.cpp b/src/vine-service.cpp index 9d3a5e5..a86e371 100755 --- a/src/vine-service.cpp +++ b/src/vine-service.cpp @@ -141,8 +141,9 @@ int _vine_service_set_type( vine_service_h service, const char *service_type) { RET_VAL_IF(service == NULL, VINE_ERROR_INVALID_PARAMETER, "service is NULL"); + RET_VAL_IF(service_type == NULL, VINE_ERROR_INVALID_PARAMETER, "service_type is NULL"); RET_VAL_IF(_vine_service_check_service_type(service_type) == false, - VINE_ERROR_INVALID_PARAMETER, "invalid length of service_type"); + VINE_ERROR_INVALID_PARAMETER, "invalid length of service_type[%s]", service_type); vine_service_s *s = (vine_service_s *)service; strncpy(s->service_type, service_type, VINE_MAX_SERVICE_TYPE_LEN);