[libbluray-devel] Check for null

hpi1 git at videolan.org
Thu Jun 4 14:41:56 CEST 2015


libbluray | branch: master | hpi1 <hpi1 at anonymous.org> | Thu Jun  4 14:40:57 2015 +0300| [98e272260b3b2bcdf7cc21e07e37fcf8e0fa4ad0] | committer: hpi1

Check for null

Do not crash with incomplete data (ex. if parsing fails in middle of file).

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

 src/libbluray/bdnav/clpi_parse.c |   26 ++++++++++++++++----------
 1 file changed, 16 insertions(+), 10 deletions(-)

diff --git a/src/libbluray/bdnav/clpi_parse.c b/src/libbluray/bdnav/clpi_parse.c
index 1ad632c..ec57a38 100644
--- a/src/libbluray/bdnav/clpi_parse.c
+++ b/src/libbluray/bdnav/clpi_parse.c
@@ -622,10 +622,12 @@ _clean_program(CLPI_PROG_INFO *p)
 {
     int ii;
 
-    for (ii = 0; ii < p->num_prog; ii++) {
-        X_FREE(p->progs[ii].streams);
+    if (p && p->progs) {
+        for (ii = 0; ii < p->num_prog; ii++) {
+            X_FREE(p->progs[ii].streams);
+        }
+        X_FREE(p->progs);
     }
-    X_FREE(p->progs);
 }
 
 static void
@@ -633,11 +635,13 @@ _clean_cpi(CLPI_CPI *cpi)
 {
     int ii;
 
-    for (ii = 0; ii < cpi->num_stream_pid; ii++) {
-        X_FREE(cpi->entry[ii].coarse);
-        X_FREE(cpi->entry[ii].fine);
+    if (cpi && cpi->entry) {
+        for (ii = 0; ii < cpi->num_stream_pid; ii++) {
+            X_FREE(cpi->entry[ii].coarse);
+            X_FREE(cpi->entry[ii].fine);
+        }
+        X_FREE(cpi->entry);
     }
-    X_FREE(cpi->entry);
 }
 
 void
@@ -649,11 +653,13 @@ clpi_free(CLPI_CL *cl)
         return;
     }
     X_FREE(cl->clip.atc_delta);
+    if (cl->sequence.atc_seq) {
+        for (ii = 0; ii < cl->sequence.num_atc_seq; ii++) {
+            X_FREE(cl->sequence.atc_seq[ii].stc_seq);
+        }
 
-    for (ii = 0; ii < cl->sequence.num_atc_seq; ii++) {
-        X_FREE(cl->sequence.atc_seq[ii].stc_seq);
+        X_FREE(cl->sequence.atc_seq);
     }
-    X_FREE(cl->sequence.atc_seq);
 
     _clean_program(&cl->program);
     _clean_cpi(&cl->cpi);



More information about the libbluray-devel mailing list