summaryrefslogtreecommitdiff
path: root/server/thumb-server-internal.c
diff options
context:
space:
mode:
Diffstat (limited to 'server/thumb-server-internal.c')
-rwxr-xr-xserver/thumb-server-internal.c54
1 files changed, 33 insertions, 21 deletions
diff --git a/server/thumb-server-internal.c b/server/thumb-server-internal.c
index f42d1d8..3faddc7 100755
--- a/server/thumb-server-internal.c
+++ b/server/thumb-server-internal.c
@@ -246,17 +246,26 @@ static int __thumb_daemon_all_extract(uid_t uid)
break;
}
- strncpy(path, (const char *)sqlite3_column_text(sqlite_stmt, 0), sizeof(path));
- path[sizeof(path) - 1] = '\0';
+ SAFE_STRLCPY(path, (const char *)sqlite3_column_text(sqlite_stmt, 0), sizeof(path));
thumb_dbg_slog("Path : %s", path);
if (g_idx == 0) {
arr_path = (char**)malloc(sizeof(char*));
arr_uid = (uid_t*)malloc(sizeof(uid_t));
+ if (arr_path == NULL || arr_uid == NULL) {
+ SAFE_FREE(arr_path);
+ SAFE_FREE(arr_uid);
+ return MS_MEDIA_ERR_OUT_OF_MEMORY;
+ }
} else {
arr_path = (char**)realloc(arr_path, (g_idx + 1) * sizeof(char*));
arr_uid = (uid_t*)realloc(arr_uid, (g_idx + 1) * sizeof(uid_t));
+ if (arr_path == NULL || arr_uid == NULL) {
+ SAFE_FREE(arr_path);
+ SAFE_FREE(arr_uid);
+ return MS_MEDIA_ERR_OUT_OF_MEMORY;
+ }
}
arr_uid[g_idx] = uid;
arr_path[g_idx++] = strdup(path);
@@ -674,7 +683,6 @@ int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg)
int thumb_h = 0;
int origin_w = 0;
int origin_h = 0;
- int max_length = 0;
char *thumb_path = NULL;
int need_update_db = 0;
int alpha = 0;
@@ -691,9 +699,8 @@ int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg)
media_thumb_format thumb_format = MEDIA_THUMB_BGRA;
thumb_w = req_msg->thumb_width;
thumb_h = req_msg->thumb_height;
+ memset(res_msg->dst_path, 0, MAX_FILEPATH_LEN);
thumb_path = res_msg->dst_path;
- thumb_path[0] = '\0';
- max_length = sizeof(res_msg->dst_path) -1;
if (!g_file_test(origin_path, G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR)) {
thumb_err("origin_path does not exist in file system.");
@@ -707,7 +714,7 @@ int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg)
}
if (msg_type == THUMB_REQUEST_DB_INSERT) {
- err = _media_thumb_get_thumb_from_db_with_size(origin_path, thumb_path, max_length, &need_update_db, &origin_w, &origin_h);
+ err = _media_thumb_get_thumb_from_db_with_size(origin_path, thumb_path, MAX_FILEPATH_LEN, &need_update_db, &origin_w, &origin_h);
if (err == MS_MEDIA_ERR_NONE) {
res_msg->origin_width = origin_w;
res_msg->origin_height = origin_h;
@@ -715,31 +722,27 @@ int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg)
return MS_MEDIA_ERR_NONE;
} else {
if (strlen(thumb_path) == 0) {
- err = _media_thumb_get_hash_name(origin_path, thumb_path, max_length, req_msg->uid);
+ err = _media_thumb_get_hash_name(origin_path, thumb_path, MAX_FILEPATH_LEN, req_msg->uid);
if (err != MS_MEDIA_ERR_NONE) {
thumb_err("_media_thumb_get_hash_name failed - %d", err);
- strncpy(thumb_path, THUMB_EMPTY_STR, max_length);
+ SAFE_STRLCPY(thumb_path, THUMB_EMPTY_STR, MAX_FILEPATH_LEN);
_media_thumb_db_disconnect();
return err;
}
-
- thumb_path[strlen(thumb_path)] = '\0';
}
}
} else if (msg_type == THUMB_REQUEST_SAVE_FILE) {
- strncpy(thumb_path, req_msg->dst_path, max_length);
+ SAFE_STRLCPY(thumb_path, req_msg->dst_path, MAX_FILEPATH_LEN);
} else if (msg_type == THUMB_REQUEST_ALL_MEDIA) {
- err = _media_thumb_get_hash_name(origin_path, thumb_path, max_length, req_msg->uid);
+ err = _media_thumb_get_hash_name(origin_path, thumb_path, MAX_FILEPATH_LEN, req_msg->uid);
if (err != MS_MEDIA_ERR_NONE) {
thumb_err("_media_thumb_get_hash_name failed - %d", err);
- strncpy(thumb_path, THUMB_EMPTY_STR, max_length);
+ SAFE_STRLCPY(thumb_path, THUMB_EMPTY_STR, MAX_FILEPATH_LEN);
_media_thumb_db_disconnect();
return err;
}
-
- thumb_path[strlen(thumb_path)] = '\0';
}
thumb_dbg_slog("Thumb path : %s", thumb_path);
@@ -753,7 +756,7 @@ int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg)
if (err != MS_MEDIA_ERR_NONE) {
thumb_err("_thumbnail_get_data failed - %d", err);
SAFE_FREE(data);
- strncpy(thumb_path, THUMB_EMPTY_STR, max_length);
+ SAFE_STRLCPY(thumb_path, THUMB_EMPTY_STR, MAX_FILEPATH_LEN);
goto DB_UPDATE;
}
@@ -785,7 +788,7 @@ int _media_thumb_process(thumbMsg *req_msg, thumbMsg *res_msg)
SAFE_FREE(data);
if (msg_type == THUMB_REQUEST_DB_INSERT || msg_type == THUMB_REQUEST_ALL_MEDIA) {
- strncpy(thumb_path, THUMB_EMPTY_STR, max_length);
+ SAFE_STRLCPY(thumb_path, THUMB_EMPTY_STR, MAX_FILEPATH_LEN);
}
_media_thumb_db_disconnect();
return err;
@@ -846,21 +849,30 @@ _media_thumb_process_raw(thumbMsg *req_msg, thumbMsg *res_msg)
thumb_w = req_msg->thumb_width;
thumb_h = req_msg->thumb_height;
- err = _thumbnail_get_raw_data(origin_path, thumb_format, &thumb_w, &thumb_h, &data, &thumb_size);
+ res_msg->msg_type = THUMB_RESPONSE_RAW_DATA;
+ err = _thumbnail_get_raw_data(origin_path, thumb_format, &thumb_w, &thumb_h, &data, &thumb_size);
if (err != MS_MEDIA_ERR_NONE) {
thumb_err("_thumbnail_get_data failed - %d", err);
+ res_msg->status = err;
+ res_msg->thumb_size = 0;
SAFE_FREE(data);
+
+ return err;
}
- res_msg->msg_type = THUMB_RESPONSE_RAW_DATA;
res_msg->thumb_width = thumb_w;
res_msg->thumb_height = thumb_h;
res_msg->thumb_size = thumb_size;
res_msg->thumb_data = malloc(thumb_size * sizeof(unsigned char));
- memcpy(res_msg->thumb_data, data, thumb_size);
+ if (res_msg->thumb_data != NULL) {
+ memcpy(res_msg->thumb_data, data, thumb_size);
+ } else {
+ thumb_err("Allocation failed");
+ err = MS_MEDIA_ERR_OUT_OF_MEMORY;
+ }
SAFE_FREE(data);
- return MS_MEDIA_ERR_NONE;
+ return err;
}