#include <errno.h>
#include <dirent.h>
#include <fcntl.h>
+#include <linux/limits.h>
#ifndef EXPORT_API
#define EXPORT_API __attribute__((visibility("default")))
static char* __convert_sticker_uri(char *uri, const char *appid, const char *app_path)
{
int ret;
+ char *copy_uri = (char *)calloc(PATH_MAX, sizeof(char));
+ if (copy_uri == NULL) {
+ LOGE("failed to allocate memory");
+ return NULL;
+ }
+ strncpy(copy_uri, uri, PATH_MAX - 1);
__remove_app_path(uri, app_path);
int len = strlen(STICKER_DIRECTORY) + strlen(appid) + strlen(uri) + 2;
char *new_path = (char *)calloc(len, sizeof(char));
- if (new_path == NULL)
- return NULL;
+ if (new_path == NULL) {
+ LOGE("failed to allocate memory");
+ ret = -1;
+ goto cleanup;
+ }
snprintf(new_path, len, "%s/%s%s",STICKER_DIRECTORY, appid, uri);
goto cleanup;
}
- if (__file_copy(uri, new_path) == -1) {
+ if (__file_copy(copy_uri, new_path) == -1) {
strerror_r(errno, error_buffer, MAX_ERROR_BUFFER);
LOGE("failed to copy sticker file : %s", error_buffer);
ret = -1;
goto cleanup;
}
- ret = unlink(uri);
+ ret = unlink(copy_uri);
if (ret != 0) {
strerror_r(errno, error_buffer, MAX_ERROR_BUFFER);
LOGE("failed to remove sticker file : %s", error_buffer);
LOGE("failed to change ownership");
cleanup:
+ free(copy_uri);
+ copy_uri = NULL;
+
if (ret == 0) {
return new_path;
} else {
- free(new_path);
- new_path = NULL;
+ if (new_path) {
+ free(new_path);
+ new_path = NULL;
+ }
return NULL;
}
}
goto free_memory;
char *rel_thumbnail = __get_string_from_object(info_object, "thumbnail");
- if (rel_thumbnail) {
- if (rel_thumbnail[0] != '\0')
+ if (rel_thumbnail && rel_thumbnail[0] != '\0') {
+ if (access(rel_thumbnail, F_OK) == 0) {
thumbnail_path = __convert_sticker_uri(rel_thumbnail, appid, app_path);
-
+ } else {
+ int len = strlen(app_path) + strlen(rel_thumbnail) + 2;
+ char *new_thumbnail_path = (char *)calloc(len, sizeof(char));
+ if (new_thumbnail_path) {
+ if (rel_thumbnail[0] == '/')
+ snprintf(new_thumbnail_path, len, "%s%s",app_path, rel_thumbnail);
+ else
+ snprintf(new_thumbnail_path, len, "%s%s%s",app_path, "/", rel_thumbnail);
+
+ if (access(new_thumbnail_path, F_OK) == 0)
+ thumbnail_path = __convert_sticker_uri(new_thumbnail_path, appid, app_path);
+
+ free(new_thumbnail_path);
+ new_thumbnail_path = NULL;
+ }
+ }
free(rel_thumbnail);
}