Ensure null-terminated string 14/263614/1 submit/tizen/20210907.051033
authorCheoleun Moon <chleun.moon@samsung.com>
Tue, 7 Sep 2021 04:46:01 +0000 (13:46 +0900)
committerCheoleun Moon <chleun.moon@samsung.com>
Tue, 7 Sep 2021 04:46:06 +0000 (13:46 +0900)
Change-Id: I9dc10563bf3b321bfdca92d581fe491ca15a84e6
Signed-off-by: Cheoleun Moon <chleun.moon@samsung.com>
src/vine-disc.cpp
src/vine-dp.cpp
src/vine-service.cpp

index 084172d47fd6868aa14fefd2f6034a1fd52ff45b..cc994fffa397985143448015db36f34fcb357662 100755 (executable)
@@ -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;
index d1b883b8614b246605d1b12eab121f6c60db9160..c9475ee9a2a979be3c69f04529d8b0d6dc13ed31 100755 (executable)
@@ -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<string, string> &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;
index 9d3a5e5c393b0a624d1db67497e6611ff3522a7e..a86e371376047a0b350b79044ef30f8226a966ac 100755 (executable)
@@ -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);