str[len - 1] = '\0';
for (i = 1; i <= 9; ++i) {
- snprintf(str2, sizeof(str2), "%s%d", str, i);
+ if ((ret = snprintf(str2, sizeof(str2), "%s%d", str, i)) > sizeof(str2) - 1) {
+ _E("Filename is longer than buffer. Need %d size of buffer.", ret + 1);
+ continue;
+ }
+
if (access(str2, R_OK) != 0)
continue;
char mmc_path[FILE_NAME_LEN_MAX + 1] = {0, };
for (i = 0; i < DIR_NUM; ++i) {
- snprintf(mmc_path, sizeof(mmc_path), "%s/%s", mount_path, mmc_default_path[i]);
+ if ((ret = snprintf(mmc_path, sizeof(mmc_path), "%s/%s", mount_path, mmc_default_path[i])) > sizeof(mmc_path) - 1) {
+ _E("Path is longer than buffer. Need %d size of buffer.", ret + 1);
+ continue;
+ }
+
if (!g_file_test(mmc_path, G_FILE_TEST_IS_DIR)) {
_D("Path(%s) did not exist.", mmc_path);
ret = mkdir(mmc_path, 0777);
continue;
pid = atoi(dir->d_name);
- snprintf(buf, PATH_MAX, "/proc/%d/cmdline", pid);
+ if ((ret = snprintf(buf, PATH_MAX, "/proc/%d/cmdline", pid)) > PATH_MAX - 1) {
+ _E("File path is longer than buffer. Need %d size of buffer.", ret + 1);
+ continue;
+ }
fd = open(buf, O_RDONLY);
if (fd < 0)
continue;
cmdline[ret] = '\0';
- snprintf(buf, PATH_MAX, "/proc/%d/fd", pid);
+ if ((ret = snprintf(buf, PATH_MAX, "/proc/%d/fd", pid)) > PATH_MAX - 1) {
+ _E("File path is longer than buffer. Need %d size of buffer.", ret + 1);
+ continue;
+ }
+
dp_child = opendir(buf);
if (!dp_child)
continue;
if (ret != 0)
break;
- snprintf(check_path, PATH_MAX, "%s/%s", buf, dir_child->d_name);
+ if ((ret = snprintf(check_path, PATH_MAX, "%s/%s", buf, dir_child->d_name)) > PATH_MAX - 1) {
+ _E("File path is longer than buffer. Need %d size of buffer.", ret + 1);
+ continue;
+ }
if (readlink(check_path, buf2, PATH_MAX) < 0)
continue;
if (dir->d_type != DT_REG)
continue;
- snprintf(path, sizeof(path), "%s/%s", PLUGIN_PATH, dir->d_name);
+ if ((ret = snprintf(path, sizeof(path), "%s/%s", PLUGIN_PATH, dir->d_name)) > sizeof(path) - 1) {
+ _E("Module path is longer than buffer. Need %d size of buffer.", ret + 1);
+ continue;
+ }
+
ret = storaged_open_module(path, &plugin);
if (ret < 0) {
_E("Failed to open module(%s): %d", path, ret);