Make minor defect fixes to dvdnav searching.c
From: Erik Hovland <erik@hovland.org>
1. length - offset might produce an unsigned underflow (which means
checking against less then zero is useless
2. new_vobu might be used uninitialized
3. The vm lock needs to be released in the error path
4. stime should be index as i-1 because it is only 19 values big
5. Another vm lock release in an error path
---
mythtv/libs/libmythdvdnav/dvdnav/searching.c | 8 +++++---
1 files changed, 5 insertions(+), 3 deletions(-)
diff --git a/mythtv/libs/libmythdvdnav/dvdnav/searching.c b/mythtv/libs/libmythdvdnav/dvdnav/searching.c
index dab2ce9..461aecf 100644
a
|
b
|
dvdnav_status_t dvdnav_sector_search(dvdnav_t *this, |
272 | 272 | target += offset; |
273 | 273 | break; |
274 | 274 | case SEEK_END: |
275 | | if(length - offset < 0) { |
| 275 | if(length < offset) { |
276 | 276 | printerr("Request to seek before start."); |
277 | 277 | pthread_mutex_unlock(&this->vm_lock); |
278 | 278 | return DVDNAV_STATUS_ERR; |
… |
… |
dvdnav_status_t dvdnav_relative_time_search(dvdnav_t *this, |
636 | 636 | return DVDNAV_STATUS_ERR; |
637 | 637 | } |
638 | 638 | |
639 | | uint32_t cur_vobu, new_vobu, start, offset; |
| 639 | uint32_t cur_vobu, new_vobu = 0, start, offset; |
640 | 640 | uint32_t first_cell_nr, last_cell_nr, cell_nr; |
641 | 641 | cell_playback_t *cell; |
642 | 642 | int i, length, scan_admap; |
… |
… |
dvdnav_status_t dvdnav_relative_time_search(dvdnav_t *this, |
658 | 658 | last_cell_nr = state->pgc->nr_of_cells - 1; |
659 | 659 | } else { |
660 | 660 | printerr("dvdnav_time_relative_time_search: works only if pgc_based is enabled"); |
| 661 | pthread_mutex_unlock(&this->vm_lock); |
661 | 662 | return DVDNAV_STATUS_ERR; |
662 | 663 | } |
663 | 664 | |
… |
… |
dvdnav_status_t dvdnav_relative_time_search(dvdnav_t *this, |
666 | 667 | dsi = dvdnav_get_current_nav_dsi(this); |
667 | 668 | if (length > 0) { |
668 | 669 | for (i = 1; i <= 19; i++) { |
669 | | if (stime[i]/2.0 <= length/2.0) { |
| 670 | if (stime[i-1]/2.0 <= length/2.0) { |
670 | 671 | offset = dsi->vobu_sri.fwda[i]; |
671 | 672 | if (offset >> 31) { |
672 | 673 | new_vobu = cur_vobu + (offset & 0xffff); |
… |
… |
dvdnav_status_t dvdnav_relative_time_search(dvdnav_t *this, |
707 | 708 | if (scan_admap) |
708 | 709 | { |
709 | 710 | if (dvdnav_scan_admap(this, state->domain, offset, &new_vobu) == DVDNAV_STATUS_ERR) |
| 711 | pthread_mutex_unlock(&this->vm_lock); |
710 | 712 | return DVDNAV_STATUS_ERR; |
711 | 713 | } |
712 | 714 | start = state->pgc->cell_playback[cell_nr].first_sector; |