From b95435b3b1c8b6abd6406c93a08c98336cfaad61 Mon Sep 17 00:00:00 2001 From: Seunghun Lee Date: Tue, 4 Feb 2020 19:53:48 +0900 Subject: [PATCH] e_info_client_screen_recorder: fix warning format-truncation Change-Id: I92a814b25c23f3dce3dbc2ddb3b874c452757e57 --- src/bin/e_info_client_screen_recorder.c | 66 ++++++++++++++++--------- 1 file changed, 42 insertions(+), 24 deletions(-) diff --git a/src/bin/e_info_client_screen_recorder.c b/src/bin/e_info_client_screen_recorder.c index aee1842470..a96710c8d1 100644 --- a/src/bin/e_info_client_screen_recorder.c +++ b/src/bin/e_info_client_screen_recorder.c @@ -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; -- 2.34.1