diff options
author | Hwankyu Jhun <h.jhun@samsung.com> | 2016-12-01 07:41:12 +0900 |
---|---|---|
committer | Hwankyu Jhun <h.jhun@samsung.com> | 2016-12-01 07:43:05 +0900 |
commit | 32b115190bb935b20a9a632ebb5895c7db50ea32 (patch) | |
tree | 7d6c9b3b718e971b24b73a3741e682b688807a90 | |
parent | e47255803c134114dbea6a09b74bf344c7ff5afd (diff) | |
download | xdgmime-32b115190bb935b20a9a632ebb5895c7db50ea32.tar.gz xdgmime-32b115190bb935b20a9a632ebb5895c7db50ea32.tar.bz2 xdgmime-32b115190bb935b20a9a632ebb5895c7db50ea32.zip |
Add exception handlingsubmit/tizen_3.0/20161202.062936
Change-Id: I3770d15860345ce232d54b0e013184e8086ed079
Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
-rw-r--r-- | xdgmime/src/xdgmime.c | 39 | ||||
-rw-r--r-- | xdgmime/src/xdgmimecache.c | 7 | ||||
-rw-r--r-- | xdgmime/src/xdgmimemagic.c | 5 |
3 files changed, 43 insertions, 8 deletions
diff --git a/xdgmime/src/xdgmime.c b/xdgmime/src/xdgmime.c index 3ec0969..9c8f9db 100644 --- a/xdgmime/src/xdgmime.c +++ b/xdgmime/src/xdgmime.c @@ -146,6 +146,9 @@ xdg_mime_init_from_directory (const char *directory) assert (directory != NULL); file_name = malloc (strlen (directory) + strlen ("/mime/mime.cache") + 1); + if (file_name == NULL) + return TRUE; + strcpy (file_name, directory); strcat (file_name, "/mime/mime.cache"); if (stat (file_name, &st) == 0) { @@ -156,16 +159,22 @@ xdg_mime_init_from_directory (const char *directory) xdg_dir_time_list_add (file_name, st.st_mtime); _caches = realloc (_caches, sizeof (XdgMimeCache *) * (n_caches + 2)); - _caches[n_caches] = cache; - _caches[n_caches + 1] = NULL; - n_caches++; - - return FALSE; - } + if (_caches != NULL) + { + _caches[n_caches] = cache; + _caches[n_caches + 1] = NULL; + n_caches++; + + return FALSE; + } + } } free (file_name); file_name = malloc (strlen (directory) + strlen ("/mime/globs2") + 1); + if (file_name == NULL) + return TRUE; + strcpy (file_name, directory); strcat (file_name, "/mime/globs2"); if (stat (file_name, &st) == 0) { @@ -176,6 +185,9 @@ xdg_mime_init_from_directory (const char *directory) { free (file_name); file_name = malloc (strlen (directory) + strlen ("/mime/globs") + 1); + if (file_name == NULL) + return TRUE; + strcpy (file_name, directory); strcat (file_name, "/mime/globs"); if (stat (file_name, &st) == 0) { @@ -189,6 +201,9 @@ xdg_mime_init_from_directory (const char *directory) } file_name = malloc (strlen (directory) + strlen ("/mime/magic") + 1); + if (file_name == NULL) + return TRUE; + strcpy (file_name, directory); strcat (file_name, "/mime/magic"); if (stat (file_name, &st) == 0) { @@ -201,21 +216,33 @@ xdg_mime_init_from_directory (const char *directory) } file_name = malloc (strlen (directory) + strlen ("/mime/aliases") + 1); + if (file_name == NULL) + return TRUE; + strcpy (file_name, directory); strcat (file_name, "/mime/aliases"); _xdg_mime_alias_read_from_file (alias_list, file_name); free (file_name); file_name = malloc (strlen (directory) + strlen ("/mime/subclasses") + 1); + if (file_name == NULL) + return TRUE; + strcpy (file_name, directory); strcat (file_name, "/mime/subclasses"); _xdg_mime_parent_read_from_file (parent_list, file_name); free (file_name); file_name = malloc (strlen (directory) + strlen ("/mime/icons") + 1); + if (file_name == NULL) + return TRUE; + strcpy (file_name, directory); strcat (file_name, "/mime/icons"); _xdg_mime_icon_read_from_file (icon_list, file_name); free (file_name); file_name = malloc (strlen (directory) + strlen ("/mime/generic-icons") + 1); + if (file_name == NULL) + return TRUE; + strcpy (file_name, directory); strcat (file_name, "/mime/generic-icons"); _xdg_mime_icon_read_from_file (generic_icon_list, file_name); free (file_name); diff --git a/xdgmime/src/xdgmimecache.c b/xdgmime/src/xdgmimecache.c index 1e99b3e..b9244ec 100644 --- a/xdgmime/src/xdgmimecache.c +++ b/xdgmime/src/xdgmimecache.c @@ -124,7 +124,7 @@ _xdg_mime_cache_new_from_file (const char *file_name) if (fd < 0) return NULL; - + if (fstat (fd, &st) < 0 || st.st_size < 4) goto done; @@ -143,8 +143,11 @@ _xdg_mime_cache_new_from_file (const char *file_name) goto done; } - + cache = (XdgMimeCache *) malloc (sizeof (XdgMimeCache)); + if (cache == NULL) + return NULL; + cache->minor = minor; cache->ref_count = 1; cache->buffer = buffer; diff --git a/xdgmime/src/xdgmimemagic.c b/xdgmime/src/xdgmimemagic.c index a2320f5..abf6ff3 100644 --- a/xdgmime/src/xdgmimemagic.c +++ b/xdgmime/src/xdgmimemagic.c @@ -169,6 +169,9 @@ _xdg_mime_magic_read_to_newline (FILE *magic_file, len = 128; pos = 0; retval = malloc (len); + if (retval == NULL) + return NULL; + *end_of_file = FALSE; while (TRUE) @@ -186,6 +189,8 @@ _xdg_mime_magic_read_to_newline (FILE *magic_file, { len = len + 128; retval = realloc (retval, len); + if (retval == NULL) + return NULL; } } |