Blame SOURCES/CVE-2017-18198-part4.patch

578e1d
--- ./libcdio-0.92/lib/iso9660/iso9660_fs.c	2018-06-06 11:52:23.464809984 +0200
578e1d
+++ ../libcdio-fedora/libcdio-0.94/lib/iso9660/iso9660_fs.c	2018-06-05 18:18:31.235215219 +0200
578e1d
@@ -714,6 +714,7 @@
578e1d
   iso711_t i_fname;
578e1d
   unsigned int stat_len;
578e1d
   iso9660_stat_t *p_stat;
578e1d
+  bool err;
578e1d
 
578e1d
   if (!dir_len) return NULL;
578e1d
 
578e1d
@@ -730,8 +731,16 @@
578e1d
     }
578e1d
   p_stat->type    = (p_iso9660_dir->file_flags & ISO_DIRECTORY)
578e1d
     ? _STAT_DIR : _STAT_FILE;
578e1d
-  p_stat->lsn     = from_733 (p_iso9660_dir->extent);
578e1d
-  p_stat->size    = from_733 (p_iso9660_dir->size);
578e1d
+  p_stat->lsn     = from_733_with_err (p_iso9660_dir->extent, &err;;
578e1d
+  if (err) {
578e1d
+    free(p_stat);
578e1d
+    return NULL;
578e1d
+  }
578e1d
+  p_stat->size    = from_733_with_err (p_iso9660_dir->size, &err;;
578e1d
+  if (err) {
578e1d
+    free(p_stat);
578e1d
+    return NULL;
578e1d
+  }
578e1d
   p_stat->secsize = _cdio_len2blocks (p_stat->size, ISO_BLOCKSIZE);
578e1d
   p_stat->rr.b3_rock = dunno; /*FIXME should do based on mask */
578e1d
   p_stat->b_xa    = false;
578e1d
@@ -754,6 +763,7 @@
578e1d
         if (!p_stat_new)
578e1d
           {
578e1d
           cdio_warn("Couldn't calloc(1, %d)", (int)(sizeof(iso9660_stat_t)+i_rr_fname+2));
578e1d
+	  free(p_stat);
578e1d
           return NULL;
578e1d
           }
578e1d
 	memcpy(p_stat_new, p_stat, stat_len);
578e1d
@@ -1098,6 +1108,12 @@
578e1d
       p_stat = _iso9660_dir_to_statbuf (p_iso9660_dir, p_iso->b_xa,
578e1d
 					p_iso->u_joliet_level);
578e1d
 
578e1d
+      if (!p_stat) {
578e1d
+	cdio_warn("Bad directory information for %s", splitpath[0]);
578e1d
+	free(_dirbuf);
578e1d
+	return NULL;
578e1d
+      }
578e1d
+
578e1d
       cmp = strcmp(splitpath[0], p_stat->filename);
578e1d
 
578e1d
       if ( 0 != cmp && 0 == p_iso->u_joliet_level
578e1d
@@ -1283,12 +1299,15 @@
578e1d
     if (!_dirbuf)
578e1d
       {
578e1d
       cdio_warn("Couldn't calloc(1, %d)", p_stat->secsize * ISO_BLOCKSIZE);
578e1d
+      _cdio_list_free (retval, true);
578e1d
       return NULL;
578e1d
       }
578e1d
 
578e1d
     if (cdio_read_data_sectors (p_cdio, _dirbuf, p_stat->lsn,
578e1d
-				ISO_BLOCKSIZE, p_stat->secsize))
578e1d
-	return NULL;
578e1d
+				ISO_BLOCKSIZE, p_stat->secsize)) {
578e1d
+      _cdio_list_free (retval, true);
578e1d
+      return NULL;
578e1d
+    }
578e1d
 
578e1d
     while (offset < (p_stat->secsize * ISO_BLOCKSIZE))
578e1d
       {
578e1d
@@ -1401,14 +1417,14 @@
578e1d
       }
578e1d
 
578e1d
     free (_dirbuf);
578e1d
+    free(p_stat->rr.psz_symlink);
578e1d
 
578e1d
-    if (offset != (p_stat->secsize * ISO_BLOCKSIZE)) {
578e1d
-      free (p_stat);
578e1d
+    if (offset != (p_stat->secsize * ISO_BLOCKSIZE)) {
578e1d
+      free (p_stat);
578e1d
       _cdio_list_free (retval, true);
578e1d
       return NULL;
578e1d
     }
578e1d
 
578e1d
-    free (p_stat->rr.psz_symlink);
578e1d
     free (p_stat);
578e1d
     return retval;
578e1d
   }
578e1d
@@ -1528,6 +1563,16 @@
578e1d
 }
578e1d
 
578e1d
 /*!
578e1d
+  Free the passed iso9660_stat_t structure.
578e1d
+ */
578e1d
+void
578e1d
+iso9660_stat_free(iso9660_stat_t *p_stat)
578e1d
+{
578e1d
+  if (p_stat != NULL)
578e1d
+    free(p_stat);
578e1d
+}
578e1d
+
578e1d
+/*!
578e1d
   Return true if ISO 9660 image has extended attrributes (XA).
578e1d
 */
578e1d
 bool
578e1d
@@ -1580,11 +1625,11 @@
578e1d
       if ( have_rr != yep) {
578e1d
 	have_rr = iso_have_rr_traverse (p_iso, p_stat, &splitpath[1], pu_file_limit);
578e1d
       }
578e1d
+      free(p_stat);
578e1d
       if (have_rr != nope) {
578e1d
 	free (_dirbuf);
578e1d
 	return have_rr;
578e1d
       }
578e1d
-      free(p_stat);
578e1d
 
578e1d
       offset += iso9660_get_dir_len(p_iso9660_dir);
578e1d
       *pu_file_limit = (*pu_file_limit)-1;