summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJiyong Min <jiyong.min@samsung.com>2017-04-25 04:19:00 (GMT)
committerJiyong Min <jiyong.min@samsung.com>2017-04-25 05:06:00 (GMT)
commit06a75284fb5bf7f8ddcd428a507b3efc81af7db4 (patch)
tree9ab5c52bdbed68f0aed710d0c08a80390211a28a
parent7f0656b53cddb9d9ae44a97041a81b4cd1415130 (diff)
downloadlibmedia-thumbnail-06a75284fb5bf7f8ddcd428a507b3efc81af7db4.zip
libmedia-thumbnail-06a75284fb5bf7f8ddcd428a507b3efc81af7db4.tar.gz
libmedia-thumbnail-06a75284fb5bf7f8ddcd428a507b3efc81af7db4.tar.bz2
Modify null pointer dereferenced in _media_thumb_get_thumb_path_from_dbsubmit/tizen/20170425.054247accepted/tizen/unified/20170426.061631refs/changes/48/126748/3
Change-Id: Iacb19869df0023972bc4e04872864186be3bc4b4 Signed-off-by: Jiyong Min <jiyong.min@samsung.com>
-rw-r--r--packaging/libmedia-thumbnail.spec2
-rwxr-xr-xsrc/include/util/media-thumb-db.h3
-rwxr-xr-xsrc/util/media-thumb-db.c132
3 files changed, 113 insertions, 24 deletions
diff --git a/packaging/libmedia-thumbnail.spec b/packaging/libmedia-thumbnail.spec
index 87fe5f5..7a104bf 100644
--- a/packaging/libmedia-thumbnail.spec
+++ b/packaging/libmedia-thumbnail.spec
@@ -1,6 +1,6 @@
Name: libmedia-thumbnail
Summary: Media thumbnail service library for multimedia applications
-Version: 0.2.3
+Version: 0.2.4
Release: 0
Group: Multimedia/Libraries
License: Apache-2.0 and PD
diff --git a/src/include/util/media-thumb-db.h b/src/include/util/media-thumb-db.h
index 23ac277..7f641c7 100755
--- a/src/include/util/media-thumb-db.h
+++ b/src/include/util/media-thumb-db.h
@@ -25,6 +25,9 @@
#ifndef _MEDIA_THUMB_DB_H_
#define _MEDIA_THUMB_DB_H_
+#define STRING_VALID(str) \
+ ((str != NULL && strlen(str) > 0) ? TRUE : FALSE)
+
#define MEDIA_DATABASE_NAME MEDIA_DB_NAME /* defined in media-util.h */
#define SELECT_PATH_FROM_UNEXTRACTED_THUMB_MEDIA "SELECT path from media where thumbnail_path is null and validity=1 and (media_type=0 or media_type=1);"
diff --git a/src/util/media-thumb-db.c b/src/util/media-thumb-db.c
index 62ff2cb..7ce5d31 100755
--- a/src/util/media-thumb-db.c
+++ b/src/util/media-thumb-db.c
@@ -49,9 +49,22 @@ int _media_thumb_get_type_from_db(sqlite3 *handle,
thumb_err("DB handle is NULL");
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
+ if (!STRING_VALID(origin_path)) {
+ thumb_err("Invalid origin_path");
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
path_string = sqlite3_mprintf("%s", origin_path);
+ if (!STRING_VALID(path_string)) {
+ thumb_err("Memory allocation is failed");
+ return MS_MEDIA_ERR_OUT_OF_MEMORY;
+ }
query_string = sqlite3_mprintf(SELECT_TYPE_BY_PATH, path_string);
+ if (!STRING_VALID(query_string)) {
+ thumb_err("Memory allocation is failed");
+ sqlite3_free(path_string);
+ return MS_MEDIA_ERR_OUT_OF_MEMORY;
+ }
thumb_dbg("Query: %s", query_string);
@@ -88,16 +101,30 @@ int _media_thumb_get_wh_from_db(sqlite3 *handle,
if (handle == NULL) {
thumb_err("DB handle is NULL");
- return -1;
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+ if (!STRING_VALID(origin_path)) {
+ thumb_err("Invalid origin_path");
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
}
- int err = -1;
+ int err = MS_MEDIA_ERR_NONE;
char *path_string = NULL;
char *query_string = NULL;
sqlite3_stmt *stmt = NULL;
path_string = sqlite3_mprintf("%s", origin_path);
+ if (!STRING_VALID(path_string)) {
+ thumb_err("Memory allocation is failed");
+ return MS_MEDIA_ERR_OUT_OF_MEMORY;
+ }
+
query_string = sqlite3_mprintf(SELECT_WH_BY_PATH, path_string);
+ if (!STRING_VALID(query_string)) {
+ thumb_err("Memory allocation is failed");
+ sqlite3_free(path_string);
+ return MS_MEDIA_ERR_OUT_OF_MEMORY;
+ }
thumb_dbg_slog("Query: %s", query_string);
@@ -108,14 +135,14 @@ int _media_thumb_get_wh_from_db(sqlite3 *handle,
if (SQLITE_OK != err) {
thumb_err("prepare error [%s]", sqlite3_errmsg(handle));
- return -1;
+ return MS_MEDIA_ERR_DB_INTERNAL;
}
err = sqlite3_step(stmt);
if (err != SQLITE_ROW) {
thumb_err("end of row [%s]", sqlite3_errmsg(handle));
sqlite3_finalize(stmt);
- return -1;
+ return MS_MEDIA_ERR_DB_INTERNAL;
}
*width = sqlite3_column_int(stmt, 0);
@@ -134,16 +161,30 @@ int _media_thumb_get_thumb_path_from_db(sqlite3 *handle,
if (handle == NULL) {
thumb_err("DB handle is NULL");
- return -1;
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+ if (!STRING_VALID(origin_path)) {
+ thumb_err("Invalid origin_path");
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
}
- int err = -1;
+ int err = MS_MEDIA_ERR_NONE;
char *path_string = NULL;
char *query_string = NULL;
sqlite3_stmt *stmt = NULL;
path_string = sqlite3_mprintf("%s", origin_path);
+ if (!STRING_VALID(path_string)) {
+ thumb_err("Memory allocation is failed");
+ return MS_MEDIA_ERR_OUT_OF_MEMORY;
+ }
+
query_string = sqlite3_mprintf(SELECT_MEDIA_BY_PATH, path_string);
+ if (!STRING_VALID(query_string)) {
+ thumb_err("Memory allocation is failed");
+ sqlite3_free(path_string);
+ return MS_MEDIA_ERR_OUT_OF_MEMORY;
+ }
thumb_dbg_slog("Query: %s", query_string);
@@ -154,14 +195,14 @@ int _media_thumb_get_thumb_path_from_db(sqlite3 *handle,
if (SQLITE_OK != err) {
thumb_err("prepare error [%s]", sqlite3_errmsg(handle));
- return -1;
+ return MS_MEDIA_ERR_DB_INTERNAL;
}
err = sqlite3_step(stmt);
if (err != SQLITE_ROW) {
thumb_err("end of row [%s]", sqlite3_errmsg(handle));
sqlite3_finalize(stmt);
- return -1;
+ return MS_MEDIA_ERR_DB_INTERNAL;
}
if (sqlite3_column_text(stmt, 0))
@@ -188,10 +229,29 @@ int _media_thumb_update_thumb_path_to_db(sqlite3 *handle,
thumb_err("DB handle is NULL");
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
+ if (!STRING_VALID(origin_path)) {
+ thumb_err("Invalid origin_path");
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
path_string = sqlite3_mprintf("%s", origin_path);
+ if (!STRING_VALID(path_string)) {
+ thumb_err("Memory allocation is failed");
+ return MS_MEDIA_ERR_OUT_OF_MEMORY;
+ }
thumbpath_string = sqlite3_mprintf("%s", thumb_path);
+ if (!STRING_VALID(thumbpath_string)) {
+ thumb_err("Memory allocation is failed");
+ sqlite3_free(path_string);
+ return MS_MEDIA_ERR_OUT_OF_MEMORY;
+ }
query_string = sqlite3_mprintf(UPDATE_THUMB_BY_PATH, thumbpath_string, path_string);
+ if (!STRING_VALID(query_string)) {
+ thumb_err("Memory allocation is failed");
+ sqlite3_free(path_string);
+ sqlite3_free(thumbpath_string);
+ return MS_MEDIA_ERR_OUT_OF_MEMORY;
+ }
err = media_db_request_update_db(query_string, uid);
if (err != MS_MEDIA_ERR_NONE) {
@@ -221,9 +281,22 @@ int _media_thumb_update_wh_to_db(sqlite3 *handle,
thumb_err("DB handle is NULL");
return MS_MEDIA_ERR_INVALID_PARAMETER;
}
+ if (!STRING_VALID(origin_path)) {
+ thumb_err("Invalid origin_path");
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
path_string = sqlite3_mprintf("%s", origin_path);
+ if (!STRING_VALID(path_string)) {
+ thumb_err("Memory allocation is failed");
+ return MS_MEDIA_ERR_OUT_OF_MEMORY;
+ }
query_string = sqlite3_mprintf(UPDATE_WH_BY_PATH, width, height, path_string);
+ if (!STRING_VALID(query_string)) {
+ thumb_err("Memory allocation is failed");
+ sqlite3_free(path_string);
+ return MS_MEDIA_ERR_OUT_OF_MEMORY;
+ }
err = media_db_request_update_db(query_string, uid);
if (err != MS_MEDIA_ERR_NONE) {
@@ -251,11 +324,24 @@ int _media_thumb_update_thumb_path_wh_to_db(sqlite3 *handle,
if (handle == NULL) {
thumb_err("DB handle is NULL");
- return -1;
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
+ }
+ if (!STRING_VALID(origin_path)) {
+ thumb_err("Invalid origin_path");
+ return MS_MEDIA_ERR_INVALID_PARAMETER;
}
path_string = sqlite3_mprintf("%s", origin_path);
+ if (!STRING_VALID(path_string)) {
+ thumb_err("Memory allocation is failed");
+ return MS_MEDIA_ERR_OUT_OF_MEMORY;
+ }
query_string = sqlite3_mprintf(UPDATE_THUMB_WH_BY_PATH, thumb_path, width, height, path_string);
+ if (!STRING_VALID(query_string)) {
+ thumb_err("Memory allocation is failed");
+ sqlite3_free(path_string);
+ return MS_MEDIA_ERR_OUT_OF_MEMORY;
+ }
err = media_db_request_update_db(query_string, uid);
if (err != MS_MEDIA_ERR_NONE) {
@@ -304,19 +390,19 @@ int _media_thumb_get_thumb_from_db(const char *origin_path,
int max_length,
int *need_update_db)
{
- int err = -1;
+ int err = MS_MEDIA_ERR_NONE;
//err = minfo_get_thumb_path(mb_svc_handle, origin_path, thumb_path, max_length);
err = _media_thumb_get_thumb_path_from_db(db_handle, origin_path, thumb_path, max_length);
- if (err < 0) {
+ if (err != MS_MEDIA_ERR_NONE) {
thumb_warn("Original path doesn't exist in DB");
- return -1;
+ return err;
}
if (strlen(thumb_path) == 0) {
thumb_warn("thumb path doesn't exist in DB");
*need_update_db = 1;
- return -1;
+ return MS_MEDIA_ERR_INTERNAL;
}
thumb_dbg_slog("Thumb path in DB is %s", thumb_path);
@@ -324,7 +410,7 @@ int _media_thumb_get_thumb_from_db(const char *origin_path,
if (!g_file_test(thumb_path, G_FILE_TEST_EXISTS)) {
thumb_warn("thumb path doesn't exist in file system");
*need_update_db = 1;
- return -1;
+ return MS_MEDIA_ERR_INTERNAL;
} else {
thumb_dbg("This thumb path already exist");
}
@@ -339,19 +425,19 @@ int _media_thumb_get_thumb_from_db_with_size(const char *origin_path,
int *width,
int *height)
{
- int err = -1;
+ int err = MS_MEDIA_ERR_NONE;
//err = minfo_get_thumb_path(mb_svc_handle, origin_path, thumb_path, max_length);
err = _media_thumb_get_thumb_path_from_db(db_handle, origin_path, thumb_path, max_length);
- if (err < 0) {
+ if (err != MS_MEDIA_ERR_NONE) {
thumb_warn("Original path doesn't exist in DB");
- return -1;
+ return err;
}
if (strlen(thumb_path) == 0) {
thumb_warn("thumb path doesn't exist in DB");
*need_update_db = 1;
- return -1;
+ return MS_MEDIA_ERR_INTERNAL;
}
thumb_dbg_slog("Thumb path in DB is %s", thumb_path);
@@ -359,14 +445,14 @@ int _media_thumb_get_thumb_from_db_with_size(const char *origin_path,
if (!g_file_test(thumb_path, G_FILE_TEST_EXISTS)) {
thumb_warn("thumb path doesn't exist in file system");
*need_update_db = 1;
- return -1;
+ return MS_MEDIA_ERR_INTERNAL;
} else {
thumb_dbg("This thumb path already exist");
int orig_w = 0;
int orig_h = 0;
err = _media_thumb_get_wh_from_db(db_handle, origin_path, &orig_w, &orig_h);
- if (err < 0) {
+ if (err != MS_MEDIA_ERR_NONE) {
thumb_err("_media_thumb_get_wh_from_db failed : %d", err);
} else {
thumb_err("_media_thumb_get_wh_from_db Success ( w:%d, h:%d )", orig_w, orig_h);
@@ -388,7 +474,7 @@ int _media_thumb_update_db(const char *origin_path,
int media_type = THUMB_NONE_TYPE;
err = _media_thumb_get_type_from_db(db_handle, origin_path, &media_type);
- if (err < 0) {
+ if (err != MS_MEDIA_ERR_NONE) {
thumb_err("_media_thumb_get_type_from_db (%s) failed: %d", origin_path, err);
return err;
}
@@ -410,13 +496,13 @@ int _media_thumb_update_db(const char *origin_path,
#else
if (media_type == THUMB_IMAGE_TYPE && width > 0 && height > 0) {
err = _media_thumb_update_thumb_path_wh_to_db(db_handle, origin_path, thumb_path, width, height, uid);
- if (err < 0) {
+ if (err != MS_MEDIA_ERR_NONE) {
thumb_err("_media_thumb_update_wh_to_db (%s) failed: %d", origin_path, err);
return err;
}
} else {
err = _media_thumb_update_thumb_path_to_db(db_handle, origin_path, thumb_path, uid);
- if (err < 0) {
+ if (err != MS_MEDIA_ERR_NONE) {
thumb_err("_media_thumb_update_thumb_path_to_db (%s) failed: %d", origin_path, err);
return err;
}