summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHwankyu Jhun <h.jhun@samsung.com>2016-12-01 07:41:12 +0900
committerHwankyu Jhun <h.jhun@samsung.com>2017-10-16 19:06:32 +0900
commit497a191ad246569c576c8df15e3e2edb664edfd0 (patch)
tree563b80e0ab82e06182f75f375dce391999ad7405
parent00beaea31d6bcb7476625a0fef347897afbbeb35 (diff)
downloadxdgmime-497a191ad246569c576c8df15e3e2edb664edfd0.tar.gz
xdgmime-497a191ad246569c576c8df15e3e2edb664edfd0.tar.bz2
xdgmime-497a191ad246569c576c8df15e3e2edb664edfd0.zip
Add exception handling
Change-Id: I3770d15860345ce232d54b0e013184e8086ed079 Signed-off-by: Hwankyu Jhun <h.jhun@samsung.com>
-rw-r--r--xdgmime/src/xdgmime.c40
-rw-r--r--xdgmime/src/xdgmimecache.c11
-rw-r--r--xdgmime/src/xdgmimemagic.c11
3 files changed, 53 insertions, 9 deletions
diff --git a/xdgmime/src/xdgmime.c b/xdgmime/src/xdgmime.c
index 3ec0969..7f1dc9c 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)
{
@@ -155,17 +158,24 @@ 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++;
+ XdgMimeCache **tmp_caches = realloc (_caches, sizeof (XdgMimeCache *) * (n_caches + 2));
+ if (tmp_caches != NULL)
+ {
+ _caches = tmp_caches;
+ _caches[n_caches] = cache;
+ _caches[n_caches + 1] = NULL;
+ n_caches++;
- return FALSE;
- }
+ 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 +186,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 +202,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 +217,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..ddcb90c 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,15 @@ _xdg_mime_cache_new_from_file (const char *file_name)
goto done;
}
-
+
cache = (XdgMimeCache *) malloc (sizeof (XdgMimeCache));
+ if (cache == NULL)
+ {
+ munmap (buffer, st.st_size);
+
+ goto done;
+ }
+
cache->minor = minor;
cache->ref_count = 1;
cache->buffer = buffer;
diff --git a/xdgmime/src/xdgmimemagic.c b/xdgmime/src/xdgmimemagic.c
index a2320f5..fbc03af 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)
@@ -185,7 +188,13 @@ _xdg_mime_magic_read_to_newline (FILE *magic_file,
if (pos % 128 == 127)
{
len = len + 128;
- retval = realloc (retval, len);
+ unsigned char *tmp = realloc (retval, len);
+ if (tmp == NULL)
+ {
+ free(retval);
+ return NULL;
+ }
+ retval = tmp;
}
}