e_info_client_screen_recorder: fix warning format-truncation 70/225470/2
authorSeunghun Lee <shiin.lee@samsung.com>
Tue, 4 Feb 2020 10:53:48 +0000 (19:53 +0900)
committerSooChan Lim <sc1.lim@samsung.com>
Fri, 21 Feb 2020 06:31:34 +0000 (06:31 +0000)
Change-Id: I92a814b25c23f3dce3dbc2ddb3b874c452757e57

src/bin/e_info_client_screen_recorder.c

index 809d29c80f8d8ccc1bee27a6297a8ab60790bd14..c36d59da9a80af9802189eaedcd5f93574f53568 100644 (file)
@@ -148,39 +148,51 @@ _screen_recorder_efl_shutdown(void)
 }
 
 static Eina_Bool
-_screen_recorder_fullpath_make_with_ext(char *out, const char *filename)
+_screen_recorder_fullpath_make_with_ext(char out[PATH_MAX], const char *filename)
 {
-   char cwd[PATH_MAX], fname_with_ext[PATH_MAX] = {0,};
+   char cwd[PATH_MAX], fullname[PATH_MAX] = {0,};
    char *dot;
    const char *ext = ".mp4";
    const char *prefix = "e-screen-record";
-   int len;
+   int len_l, len;
 
+   len_l = PATH_MAX;
    if (filename)
      {
-        dot = strrchr(filename, '.');
-        if ((!dot) || (strlen(dot + 1) !=3) || (strncmp(dot, ext, strlen(ext)) != 0))
+        if (filename[0] != '/')
           {
-             /* concatenate file extention. */
-             len = strnlen(filename, PATH_MAX - 4);
-             strncat(fname_with_ext, filename, len);
-             strncat(fname_with_ext, ext, 4);
+             if (!getcwd(cwd, sizeof(cwd)))
+               snprintf(cwd, sizeof(cwd), "/tmp");
+
+             len = snprintf(fullname, len_l, "%s/%s", cwd, filename);
           }
         else
+          len = snprintf(fullname, len_l, "%s", filename);
+
+        len_l -= len;
+        if (len_l <= 0)
           {
-             strncat(fname_with_ext, filename, (PATH_MAX - 1));
-             fname_with_ext[PATH_MAX - 1] = '\0';
+             ERR("file name is too long");
+             return EINA_FALSE;
           }
 
-        if (fname_with_ext[0] != '/')
+        dot = strrchr(fullname, '.');
+        len = strlen(ext);
+        if ((!dot) ||
+            (strlen(dot) != len) ||
+            (strncmp(dot, ext, len) != 0))
           {
-             /* concatenate current working directory or '/tmp'. */
-             if (!getcwd(cwd, sizeof(cwd)))
-               snprintf(cwd, sizeof(cwd), "/tmp");
-             snprintf(out, PATH_MAX, "%s/%s", cwd, fname_with_ext);
+             /* concatenate file extention. */
+             if (len_l < (len + 1))
+               {
+                  ERR("file name is too long");
+                  return EINA_FALSE;
+               }
+
+             strncat(fullname, ext, len);
           }
-        else
-          strncpy(out, fname_with_ext, PATH_MAX);
+
+          strncpy(out, fullname, PATH_MAX);
      }
    else
      {
@@ -195,12 +207,18 @@ _screen_recorder_fullpath_make_with_ext(char *out, const char *filename)
         if (!getcwd(cwd, sizeof(cwd)))
           snprintf(cwd, sizeof(cwd), "/tmp");
 
-        snprintf(out, PATH_MAX, "%s/%s-%04d%02d%02d.%02d%02d%02d%s",
-                 cwd, prefix,
-                 t->tm_year+1900, t->tm_mon+1, t->tm_mday, t->tm_hour,
-                 t->tm_min, t->tm_sec,
-                 ext);
-        out[PATH_MAX - 1] = '\0';
+        len = snprintf(fullname, len_l, "%s/%s-%04d%02d%02d.%02d%02d%02d",
+                       cwd, prefix,
+                       t->tm_year+1900, t->tm_mon+1, t->tm_mday, t->tm_hour,
+                       t->tm_min, t->tm_sec);
+        len_l -= len;
+
+        len = strlen(ext);
+        if ((len + 1) > len_l)
+          fullname[PATH_MAX - (len + 1)] = '\0';
+
+        strncat(fullname, ext, len);
+        strncpy(out, fullname, PATH_MAX);
      }
 
    return EINA_TRUE;