*end = '\0';
snprintf(temp, PATH_MAX, "%s", temp2);
free(temp2);
- } else
- snprintf(temp, PATH_MAX, "%s/%s", root, dir_path[type]);
+ } else {
+ if ((ret = snprintf(temp, PATH_MAX, "%s/%s", root, dir_path[type])) > PATH_MAX - 1) {
+ _E("Path is longer than buffer. Need %d size of buffer.", ret + 1);
+ return STORAGE_ERROR_OUT_OF_MEMORY;
+ }
+ }
goto out;
}
if (extendedint)
return STORAGE_ERROR_INVALID_PARAMETER;
- snprintf(temp, sizeof(temp), "%s/%s", root, dir_path[type]);
+ if ((ret = snprintf(temp, sizeof(temp), "%s/%s", root, dir_path[type])) > sizeof(temp) - 1) {
+ _E("Path is longer than buffer. Need %d size of buffer.", ret + 1);
+ return STORAGE_ERROR_OUT_OF_MEMORY;
+ }
out:
*path = strdup(temp);