[libbluray-devel] Check str_printf result

hpi1 git at videolan.org
Thu Jun 4 14:43:40 CEST 2015


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Thu Jun  4 14:31:23 2015 +0300| [ebdcfe27418fea53689c1287b7303d0c03243a82] | committer: hpi1

Check str_printf result

> http://git.videolan.org/gitweb.cgi/libbluray.git/?a=commit;h=ebdcfe27418fea53689c1287b7303d0c03243a82
---

 src/libbluray/bdj/bdj.c          |    4 ++++
 src/libbluray/bdnav/navigation.c |   11 ++++++++---
 src/libbluray/bluray.c           |   26 +++++++++++++++++++-------
 3 files changed, 31 insertions(+), 10 deletions(-)

diff --git a/src/libbluray/bdj/bdj.c b/src/libbluray/bdj/bdj.c
index 3465c69..ef9452c 100644
--- a/src/libbluray/bdj/bdj.c
+++ b/src/libbluray/bdj/bdj.c
@@ -136,6 +136,10 @@ static void *_jvm_dlopen(const char *java_home, const char *jvm_dir, const char
 {
     if (java_home) {
         char *path = str_printf("%s/%s/%s", java_home, jvm_dir, jvm_lib);
+        if (!path) {
+            BD_DEBUG(DBG_CRIT, "out of memory\n");
+            return NULL;
+        }
         BD_DEBUG(DBG_BDJ, "Opening %s ...\n", path);
         void *h = dl_dlopen(path, NULL);
         X_FREE(path);
diff --git a/src/libbluray/bdnav/navigation.c b/src/libbluray/bdnav/navigation.c
index db7fa9f..037a09d 100644
--- a/src/libbluray/bdnav/navigation.c
+++ b/src/libbluray/bdnav/navigation.c
@@ -403,15 +403,20 @@ static void _fill_clip(NAV_TITLE *title,
     strncpy(&clip->name[5], ".m2ts", 6);
     clip->clip_id = atoi(mpls_clip[clip->angle].clip_id);
 
-    file = str_printf("%s.clpi", mpls_clip[clip->angle].clip_id);
     clpi_free(clip->cl);
-    clip->cl = clpi_get(title->disc, file);
-    X_FREE(file);
+    clip->cl = NULL;
+
+    file = str_printf("%s.clpi", mpls_clip[clip->angle].clip_id);
+    if (file) {
+        clip->cl = clpi_get(title->disc, file);
+        X_FREE(file);
+    }
     if (clip->cl == NULL) {
         clip->start_pkt = 0;
         clip->end_pkt = 0;
         return;
     }
+
     switch (connection_condition) {
         case 5:
         case 6:
diff --git a/src/libbluray/bluray.c b/src/libbluray/bluray.c
index eba9c5e..98781e2 100644
--- a/src/libbluray/bluray.c
+++ b/src/libbluray/bluray.c
@@ -2081,12 +2081,14 @@ static int _preload_textst_subpath(BLURAY *bd)
     gc_add_font(bd->graphics_controller, NULL, -1);
     for (ii = 0; ii < bd->st_textst.clip->cl->font_info.font_count; ii++) {
         char *file = str_printf("%s.otf", bd->st_textst.clip->cl->font_info.font[ii].file_id);
-        uint8_t *data = NULL;
-        size_t size = disc_read_file(bd->disc, "BDMV" DIR_SEP "AUXDATA", file, &data);
-        if (data && size > 0 && gc_add_font(bd->graphics_controller, data, size) < 0) {
-            X_FREE(data);
+        if (file) {
+            uint8_t *data = NULL;
+            size_t size = disc_read_file(bd->disc, "BDMV" DIR_SEP "AUXDATA", file, &data);
+            if (data && size > 0 && gc_add_font(bd->graphics_controller, data, size) < 0) {
+                X_FREE(data);
+            }
+            X_FREE(file);
         }
-        X_FREE(file);
     }
     gc_run(bd->graphics_controller, GC_CTRL_PG_CHARCODE, char_code, NULL);
 
@@ -2285,9 +2287,14 @@ static int _open_playlist(BLURAY *bd, const char *f_name, unsigned angle)
 
 int bd_select_playlist(BLURAY *bd, uint32_t playlist)
 {
-    char *f_name = str_printf("%05d.mpls", playlist);
+    char *f_name;
     int result;
 
+    f_name = str_printf("%05d.mpls", playlist);
+    if (!f_name) {
+        return 0;
+    }
+
     bd_mutex_lock(&bd->mutex);
 
     if (bd->title_list) {
@@ -2637,9 +2644,14 @@ BLURAY_TITLE_INFO* bd_get_title_info(BLURAY *bd, uint32_t title_idx, unsigned an
 
 BLURAY_TITLE_INFO* bd_get_playlist_info(BLURAY *bd, uint32_t playlist, unsigned angle)
 {
-    char *f_name = str_printf("%05d.mpls", playlist);
+    char *f_name;
     BLURAY_TITLE_INFO *title_info;
 
+    f_name = str_printf("%05d.mpls", playlist);
+    if (!f_name) {
+        return NULL;
+    }
+
     title_info = _get_title_info(bd, 0, playlist, f_name, angle);
 
     X_FREE(f_name);



More information about the libbluray-devel mailing list