Fix strncpy() missing null character coverity issue 00/323900/1 accepted/tizen/9.0/unified/20250512.171607
authorYunhee Seo <yuni.seo@samsung.com>
Fri, 9 May 2025 01:31:01 +0000 (10:31 +0900)
committerYunhee Seo <yuni.seo@samsung.com>
Fri, 9 May 2025 01:31:01 +0000 (10:31 +0900)
If the strncpy gets the exact length of destination,
null character can be missed.
To fix up this, null character setting explicitly is added.

Change-Id: I8537e53df5e82e63a46898363003d9734bcd731f
Signed-off-by: Yunhee Seo <yuni.seo@samsung.com>
src/service/src/plugin_push.cpp

index 0a1ba3113b67f25e468ae7810fba50660cf2e90b..614c3c04f9164e729da843d99a6dcd5ce7421571 100644 (file)
@@ -148,8 +148,10 @@ extern "C"
                        if (!ret)
                                throw std::runtime_error("Not enough memory");
 
-                       for (size_t i = 0; i < subsessions.size(); ++i)
+                       for (size_t i = 0; i < subsessions.size(); ++i) {
                                strncpy(ret[i], subsessions[i].c_str(), SUBSESSION_USER_MAXLEN);
+                               ret[i][SUBSESSION_USER_MAXLEN - 1] = '\0';
+                       }
 
                        *subsession_count = subsessions.size();
                        *subsession_list = ret;