]> git.ipfire.org Git - thirdparty/libsolv.git/commitdiff
Guard against dirpool_add_dir being called with an illegal component id
authorMichael Schroeder <mls@suse.de>
Mon, 30 Jan 2017 15:18:46 +0000 (16:18 +0100)
committerMichael Schroeder <mls@suse.de>
Mon, 30 Jan 2017 15:18:46 +0000 (16:18 +0100)
src/dirpool.c
src/repo_write.c

index 5f083616426f3d2c4d8aa09712b23538e5a9826f..fc57cc5ced08d4fd7aeaf3468967d2d1763a617a 100644 (file)
@@ -99,8 +99,10 @@ dirpool_make_dirtraverse(Dirpool *dp)
 Id
 dirpool_add_dir(Dirpool *dp, Id parent, Id comp, int create)
 {
-  Id did, d, ds, *dirtraverse;
+  Id did, d, ds;
 
+  if (comp <= 0)
+    return 0;
   if (!dp->ndirs)
     {
       if (!create)
@@ -116,8 +118,7 @@ dirpool_add_dir(Dirpool *dp, Id parent, Id comp, int create)
     dirpool_make_dirtraverse(dp);
   /* check all entries with this parent if we
    * already have this component */
-  dirtraverse = dp->dirtraverse;
-  ds = dirtraverse[parent];
+  ds = dp->dirtraverse[parent];
   while (ds)
     {
       /* ds: first component in this block
index 210636c4306b7da598ce4c09b1ca57dfff0caf51..396cd427d5344ed298971e1dad8fafe5ab9b9ba1 100644 (file)
@@ -955,6 +955,10 @@ traverse_dirs(Dirpool *dp, Id *dirmap, Id n, Id dir, Id *used)
       dirmap[n++] = sib;
     }
 
+  /* check if our block has some content */
+  if (parent == n)
+    return n - 1;      /* nope, drop parent id again */
+
   /* now go through all the siblings we just added and
    * do recursive calls on them */
   lastn = n;