[libbluray-devel] Check calloc() result

hpi1 git at videolan.org
Mon Aug 27 11:36:01 CEST 2018


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Mon Aug 27 11:10:08 2018 +0300| [d5a8287c4dec4703222292e2a9639e9e01018b59] | committer: hpi1

Check calloc() result

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

 src/libbluray/bdnav/navigation.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/src/libbluray/bdnav/navigation.c b/src/libbluray/bdnav/navigation.c
index 6a37e8eb..b7e57018 100644
--- a/src/libbluray/bdnav/navigation.c
+++ b/src/libbluray/bdnav/navigation.c
@@ -717,8 +717,13 @@ NAV_TITLE* nav_title_open(BD_DISC *disc, const char *playlist, unsigned angle)
     }
 
     // Find length in packets and end_pkt for each clip
+    if (title->pl->list_count) {
     title->clip_list.count = title->pl->list_count;
     title->clip_list.clip = calloc(title->pl->list_count, sizeof(NAV_CLIP));
+    if (!title->clip_list.clip) {
+      _nav_title_close(title);
+      return NULL;
+    }
     title->packets = 0;
     for (ii = 0; ii < title->pl->list_count; ii++) {
         MPLS_PI *pi;
@@ -731,19 +736,31 @@ NAV_TITLE* nav_title_open(BD_DISC *disc, const char *playlist, unsigned angle)
         _fill_clip(title, pi->clip, pi->connection_condition, pi->in_time, pi->out_time, pi->angle_count,
                    clip, ii, &pos, &time);
     }
+    }
 
     // sub paths
     // Find length in packets and end_pkt for each clip
     if (title->pl->sub_count > 0) {
         title->sub_path_count = title->pl->sub_count;
         title->sub_path       = calloc(title->sub_path_count, sizeof(NAV_SUB_PATH));
+        if (!title->sub_path) {
+          _nav_title_close(title);
+          return NULL;
+        }
 
         for (ss = 0; ss < title->sub_path_count; ss++) {
             NAV_SUB_PATH *sub_path = &title->sub_path[ss];
 
             sub_path->type            = title->pl->sub_path[ss].type;
             sub_path->clip_list.count = title->pl->sub_path[ss].sub_playitem_count;
+            if (!sub_path->clip_list.count)
+              continue;
+
             sub_path->clip_list.clip  = calloc(sub_path->clip_list.count, sizeof(NAV_CLIP));
+            if (!sub_path->clip_list.clip) {
+              _nav_title_close(title);
+              return NULL;
+            }
 
             pos = time = 0;
             for (ii = 0; ii < sub_path->clip_list.count; ii++) {



More information about the libbluray-devel mailing list