[libdvdnav-devel] [PATCH 1/2] Add checks to ensure state->pgc validity

Pierre Lamot pierre at videolabs.io
Tue Jan 9 15:52:50 CET 2018


---
 src/dvdnav.c     |  9 +++++++++
 src/highlight.c  | 13 +++++++++++++
 src/navigation.c |  6 ++++++
 src/vm/getset.c  |  7 +++++++
 4 files changed, 35 insertions(+)

diff --git a/src/dvdnav.c b/src/dvdnav.c
index 08ce12e..07352db 100644
--- a/src/dvdnav.c
+++ b/src/dvdnav.c
@@ -485,6 +485,9 @@ int64_t dvdnav_get_current_time(dvdnav_t *this) {
   int64_t tm=0;
   dvd_state_t *state = &this->vm->state;
 
+  if(! state->pgc)
+    return 0;
+
   for(i=0; i<state->cellN-1; i++) {
     if(!
         (state->pgc->cell_playback[i].block_type == BLOCK_TYPE_ANGLE_BLOCK &&
@@ -517,6 +520,12 @@ dvdnav_status_t dvdnav_get_next_cache_block(dvdnav_t *this, uint8_t **buf,
     this->started = 1;
   }
 
+  if (!this->vm->state.pgc) {
+      printerr("No current PGC.");
+      pthread_mutex_unlock(&this->vm_lock);
+      return DVDNAV_STATUS_ERR;
+  }
+
   state = &(this->vm->state);
   (*event) = DVDNAV_NOP;
   (*len) = 0;
diff --git a/src/highlight.c b/src/highlight.c
index b450d0d..a612d38 100644
--- a/src/highlight.c
+++ b/src/highlight.c
@@ -343,6 +343,12 @@ dvdnav_status_t dvdnav_button_activate(dvdnav_t *this, pci_t *pci) {
   }
   pthread_mutex_lock(&this->vm_lock);
 
+  if(!this->vm->state.pgc) {
+    printerr("No current PGC.");
+    pthread_mutex_unlock(&this->vm_lock);
+    return DVDNAV_STATUS_ERR;
+  }
+
   button = this->vm->state.HL_BTNN_REG >> 10;
 
   if((button <= 0) || (button > pci->hli.hl_gi.btn_ns)) {
@@ -394,6 +400,13 @@ dvdnav_status_t dvdnav_button_activate(dvdnav_t *this, pci_t *pci) {
 dvdnav_status_t dvdnav_button_activate_cmd(dvdnav_t *this, int32_t button, vm_cmd_t *cmd)
 {
   pthread_mutex_lock(&this->vm_lock);
+
+  if(!this->vm->state.pgc) {
+    printerr("No current PGC.");
+    pthread_mutex_unlock(&this->vm_lock);
+    return DVDNAV_STATUS_ERR;
+  }
+
   /* make the VM execute the appropriate code and probably
    * schedule a jump */
 #ifdef BUTTON_TESTING
diff --git a/src/navigation.c b/src/navigation.c
index 4fe4a91..8cbe63a 100644
--- a/src/navigation.c
+++ b/src/navigation.c
@@ -269,6 +269,12 @@ dvdnav_status_t dvdnav_go_up(dvdnav_t *this) {
   /* A nice easy function... delegate to the VM */
   int retval;
   pthread_mutex_lock(&this->vm_lock);
+  if (!this->vm->state.pgc) {
+    printerr("No current PGC.");
+    pthread_mutex_unlock(&this->vm_lock);
+    return DVDNAV_STATUS_ERR;
+  }
+
   retval = vm_jump_up(this->vm);
   pthread_mutex_unlock(&this->vm_lock);
 
diff --git a/src/vm/getset.c b/src/vm/getset.c
index cd0c074..f60c0da 100644
--- a/src/vm/getset.c
+++ b/src/vm/getset.c
@@ -172,6 +172,9 @@ int set_PGN(vm_t *vm) {
   int new_pgN = 0;
   int dummy, part = 0;
 
+  if ((vm->state).pgc == NULL)
+    return 0;
+
   while(new_pgN < (vm->state).pgc->nr_of_programs
         && (vm->state).cellN >= (vm->state).pgc->program_map[new_pgN])
     new_pgN++;
@@ -280,6 +283,10 @@ int get_PGCN(vm_t *vm) {
   pgcit_t *pgcit;
   int pgcN = 1;
 
+  if ((vm->state).pgc == NULL) {
+    return 0; /* error */
+  }
+
   pgcit = get_PGCIT(vm);
 
   if (pgcit) {
-- 
2.14.1



More information about the libdvdnav-devel mailing list